我可以在UI路由器解析中分组多个对象

时间:2015-09-03 08:19:48

标签: angularjs angular-ui-router

我需要在Resolve中预先加载3个服务,而不是为每个服务创建单独的服务调用,是否可以返回函数对象

我的路由器

.state('home.movies', {
                parent: 'home',
                url: '/home/movies/edit/:id',
                data: {
                    roles: []
                },
                views: {
                    'content@': {
                        templateUrl: 'views/admin/activity-edit.html',
                        controller: 'ActivityEditController'
                    }     
                },
                resolve: 
                    titles:function (MovieService){
                       return {
                           actors: function (MovieService) {                            
                              return MovieService.getActors('','','N');
                            },
                           actresses:function (MovieService) {                            
                             return ResourceService.getActresses();
                           },
                          timemap:function(MovieService){
                             return MovieService.getTimemap();                      
                           }
                       }
                    }

            });
    })

我的控制器

.controller('MovieEditController', function ($scope,titles,MovieService) {

refere就是

 $scope.moviesActors=titles.actors;

1 个答案:

答案 0 :(得分:1)

可以使用$q

resolve: {
   titles: function (MovieService, $q){
       return $q.all({
           actors: MovieService.getActors('','','N'),
           actresses: ResourceService.getActresses(),
           timemap: MovieService.getTimemap()
       });
   }
}

已解决的titles将如下所示:{ actors: [], actresses: [], timemap: {} }