Consider the code:
var myApp = angular.module('myApp', []);
Routes:
myApp.config(['$routeProvider', function($routeProvider) { $routeProvider.when('/', { templateUrl: 'app.html', controller:myAppController, resolve:{ resolveData:function(Resolver){ return Resolver(); } } }); });
Resolve:
myApp.factory('Resolver', ['$http', function($http){ return function(){ return $http({url: '/someurl',method: "GET"}).then(function(data) { // dependent call 1 $http({url: '/someotherurl',method: "GET" }).then(function(data) { }); // dependent call 2 $http({url: '/someanotherurl',method: "GET" }).then(function(data) { }); }); } }]);
Above, I nested 2 calls inside one, as they depend on the data returned by the parent call.
What I want to do : return Resolver when all of them are completed, and not just the parent call.
I cannot use $ q.all () because 2 of the calls depend on the first call.
In short, myAppController should only be loaded after all 3 calls have completed.
angularjs promise angularjs-routing
AlwaysALearner
source share