I have an angular service that fetches data that will be used by multiple controllers. I only want to fetch the data from the db once and then have the service store the data in an object which controllers can reference through the service.
I'm using ui-router with multiple and nested views. Where should I put my service fetch so that my controllers can safely reference the data knowing the service fetched it successfully?
For example:
Where would I put this:
myAngularService.GetDbData(DataId).success(function (response) {
this.myDbData = response;
});
So that in my controllers I can do this:
angular.module('myWebApp.controllers').
controller('myCtrl', function($scope, myAngularService) {
$scope.myDbData = myAngularService.myDbData;
});
I thought about using a resolve in my main state that houses all my other substates, however I'm not sure how to pass a parameter to my service that way (in this example the parameter would be DataId
).