Based on the inquiry found in this source: Global variables in AngularJS
It has been suggested that global variables can be set using a service or rootscope.
My issue lies in the fact that I am unable to access the global variable within a function, unless I pass the factory into the function. How can I retrieve the variable if it's not within a function? The challenge arises from the lack of control over the parameters of callback functions used from an external library.
Suppose my factory is structured as follows:
.factory('principal',[$q, ...etc etc function($q ...){
return{
a_variable: 'an_example'
}
]})
If I wish to access principal within a function, I can do so like this:
function example_function(principal){
puts principal.a_variable //works!
}
However, in cases where the parameters of callback functions are predetermined...
function onNotificationCallback(result){
// this function is provided to me but principal isn't a parameter
// therefore principal.a_variable is not accessible!
}
How can I overcome this limitation and access principal within this callback function?