2013-04-13 67 views
1

我想让我的angularFire集合解决路由加载。例如:angularFire路由解析

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

是否可以这样做?

回答

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 
    }); 
} 

是它主要的问题语法上的方便还是我失去了你在上面要的功能?

更新:

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. 
} 
+0

在这个方法'$ routeChangeSuccess'将要发射的'angularFire'资源得到解决之前,右:对于前$routeChangeSuccess事件被激发到解决的价值? –

+0

你是对的 - 如果你想在事件触发之前解决这个问题,你可以简单地将调用转到'angularFire'到你的解析属性中,因为它返回一个promise。我将编辑答案以提供代码片段。 – Anant

+0

Anant,您可能会看到这一点的机会,我试图使用解析功能,但它指出angularFire是一个未知的提供者(在相关的说明是angularFireCollection不适合在这种情况下由于不需要范围? )。 aF和aFC在我的代码的其他地方工作正常,但是有可能是我在配置和解决使用它时丢失的东西? – Michael