Here's the point: I'm building charts for a web application. I get the information for the charts from a single object from a webservice in java. Here's basically the format of the JSON object I'm retrieving
{ "chart1Info": [9, 42, 43, 7, 20], "chart2Info": [45, 3, 21, 34] (...and so on)}
And on my app.js (where my AngularJS code is) I have 7 controllers for the 7 charts. In each controller I'm calling the service to get the same object with all the information.
app.controller('chart1', function($scope, $http){
$http.get('//WEBSERVICE_PATH').then(function(response) {
$scope.chartData = response.data; //The JSON object
//Then I build the charts...
});
});
What I want to do is call the service 1 time only and save the object so my controllers can use it since it's the same object for every one. I tried using a main controller envolving all other controllers and setting a propertie of $rootScope to the JSON object like
$rootScope.chartData = response.data;
//Inside the $http.get() function
But it is undefined in the other controllers. Thanks for the answers