angularFire route resolution

后端 未结 1 1725
清歌不尽
清歌不尽 2021-02-11 08:14

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

App.config ($routeProvider, angularFireProvider) ->
  $rout         


        
相关标签:
1条回答
  • 2021-02-11 09:08

    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?

    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.
     }
    
    0 讨论(0)
提交回复
热议问题