I have an AngularJS service that I want to initialize with some asynchronous data. Something like this:
myModule.service(\'MyService\', function($http) {
Easiest way to fetch any initialize use ng-init directory.
Just put ng-init div scope where you want to fetch init data
index.html
index.js
$scope.init=function(){
$http({method:'GET',url:'/countries/countries.json'}).success(function(data){
alert();
$scope.countries = data;
});
};
NOTE: you can use this methodology if you do not have same code more then one place.