Hi Guys,
on my app i need a service with some important parameters for the
application working fine.
The problem is: my service loads the data using $http.get and in my
controllers and directives i need that data. However the data loading is
asynchronous and when my controller requests the data, it has not been
loaded.
How can i get this done? Load my service and $http request before
initialize controllers and directives.
I've seen some solutions using resolve, but i'm not managing the urls using
ng-route.
Here is an example of what I want:
app.service("$myService", function($http) {
var myService = {};
myService.loadData = function() {
$http.get("/mydata.json").success(function(data) {
myService.data = data;
});
};
myService.param1 = function() {
return data.param1;
};
return myService;
});
app.controller("MyController", function($scope, $myService) {
$scope.param1 = $myService.param1();
});
Anyone can help me?
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.