This should be a fairly straight forward question, but I'm stumped.
I have a service that makes an http call and then does extensive post-processing of the results. I would like the processed results to be assigned to a $scope.variable and used in several different views. The thing is I have separate controllers for each view, but I don't want each controller to call the service to have the same data fetched from a resource and post-processed once for each controller.
Super simplified I have this:
myModule.factory ('Data', function ($http, $q) {
getData: $http.get...
processData: this.getData().success(function(data){
... do a ton of cpu intensive processing ...
return processed_data
ctrl1 = function(Data,$scope) {
$scope.data = Data.processData()
}
ctrl2 = function(Data,$scope) {
$scope.data = Data.processData()
etc...
}
Obviously I would like to set $scope.data = Data.processData() just once and have it populate across all the controllers. As it stands, each controller invokes the service independently, which creates unnecessary traffic and cpu.
I'm sure there is something simple, but I can't figure it out. Is there some way of creating a "super" scope where I can define variables that are common to all controller scope?
Thanks,