angularFire路由解析 [英] angularFire route resolution

查看:142
本文介绍了angularFire路由解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对航线装载我的 angularFire 收集的决心。是这样的:

I'd like to have my angularFire collection resolve on route loading. Something like:

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

是否有可能做到这一点?

Is it possible to do this?

推荐答案

我不知道是什么原因,你要收集到有关航线装载解决,在控制器的反对 - 你能解释一下?例如,下面将工作太:

I'm not exactly sure why you want the collection to resolve on route loading, as opposed to in the controller - could you elaborate? For example, the following would work too:

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

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

Is it mainly a matter syntactic convenience or am I missing functionality you want in the above?

更新:对于 $ routeChangeSuccess 事件之前需要解决的值被激发:

Update: For the value to be resolved before the $routeChangeSuccess event is fired:

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

这篇关于angularFire路由解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆