I have a service on my angular.js app that creates a variable (filteredDataGlobal) in it's scope (self) and has another function to return that variable.
.service('Utilities',function(){
var self = this;
self.someFunction = function(){
///does calculations then assigns the results in a variable (filteredDataGlobal)
self.filteredDataGlobal = finalResults;
}
self.getFilteredData = function(){
return self.filteredDataGlobal;
};
}
The problem is self.someFunction takes time to happen (calculations made after an http request) so that when you're in a controller that has the Utilities service and try to access the self.filteredDataGlobal variable like so, it's logged as undefined
.controller('MyController', function(Utilities) {
var self = this;
self.filteredData = Utilities.getFilteredData();
console.log(self.filteredData);
})
How would I 'watch' for self.filteredDataGlobal to be ready in the Utilities function before I use it in my controller?