我想让我的angularFire集合解决路线加载问题。就像是:

App.config ($routeProvider, angularFireProvider) ->
  $routeProvider.when '/test',
    templateUrl: 'views/test.html'
    controller: 'TestCtrl'
    resolve: angularFireProvider.resolve 'testItems'


是否有可能做到这一点?

最佳答案

我不太确定为什么要让集合在路由加载时解析,而不是在控制器中解析-您能详细说明吗?例如,以下内容也可以工作:

App.config ($routeProvider, angularFireProvider) ->
  $routeProvider.when '/test',
  controller: 'TestCtrl'

function TestCtrl($scope, angularFire) {
  angularFire("https://<example>.firebaseio.com", $scope, "collection").
    then(function() {
      // The collection has been resolved and available in $scope.collection
    });
}


这主要是语法上的便利还是我上面缺少的功能?

更新:对于在触发$routeChangeSuccess事件之前要解析的值:

 App.config(['$routeProvider', 'angularFire', function($routeProvider, angularFire) {
   $routeProvider.when("/test", {
     templateUrl: 'views/test.html'
     controller: 'TestCtrl',
     resolve: {collection: angularFire("https://<example>.firebaseio.com")}
   });
 }]);

 function TestCtrl(collection) {
   // collection has already been resolved to its value.
 }

10-08 06:03