- var myApp = angular.module('myApp',[]);
路线:
- myApp.config(['$routeProvider',function($routeProvider) {
- $routeProvider.when('/',{
- templateUrl: 'app.html',controller:myAppController,resolve:{
- resolveData:function(Resolver){
- return Resolver();
- }
- }
- });
- });
解决:
- 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) {
- });
- });
- }
- }]);
上面我在一个内嵌了2个调用,因为它们依赖于父调用返回的数据.
我想做的事情:当所有这些都完成后返回解析器而不仅仅是父调用.
我不能使用$q.all(),因为其中2个调用依赖于第一个调用.
简而言之,只有在所有3个调用完成后才能加载myAppController.