J. Abrahamson
J. Abrahamson

Reputation: 74364

angularFire route resolution

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?

Upvotes: 1

Views: 812

Answers (1)

Anant
Anant

Reputation: 7428

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

Upvotes: 2

Related Questions