1

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

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

是否有可能做到这一点?

4

1 回答 1

2

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

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.
 }
于 2013-04-15T02:28:28.123 回答