I have implemented a factory in my project to share data among multiple controllers. Here is the code for my factory:
var szGetData = "some url that works";
myApp.factory('Data', function ($http) {
var eventData = {};
eventData.getEvent = function (event) {
return $http.get(szGetData, event);
}
return eventData;
});
Each of my controllers calls the factory in the same way, like this:
Data.getEvent()
.success(function (event) {
$scope.eventData = event;
})
.error(function (error) {
$scope.status = 'Unable to load customer data: ' + error.message;
});
Although everything is functioning correctly and I am able to retrieve the data, the web-service is being called three times and each controller has its own copy of the data. I would prefer to have all controllers working with the same data and only make one call to the web-service. Any suggestions on how to achieve this would be greatly appreciated.