Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular: force resolve again

My dependencies to be resolved rely on data which changes. How do you force angular to resolve dependencies again?

  $routeProvider.
  when('/blah', {
    templateUrl: '/static/views/myView.html',
    controller: 'myCtrl',
    resolve: {
        theData: function(myFactory) {
            return myFactory.promise;
        }
    }
  }).

i.e, every time this when block is executed I want to re-resolve the dependency.

Is this trivial, or not so much?

like image 840
arhoskins Avatar asked Dec 15 '14 06:12

arhoskins


1 Answers

Resolve block is rechecked every time route changes. In your case you need to return new promise each time, instead of how you are doing it currently. Looks like you cache and return always the same promise object.

resolve: {
    theData: function(myFactory) {
        return myFactory.getSomething();
    }
}

Make myFactory.getSomething return new promise in each invocation.

like image 110
dfsq Avatar answered Sep 27 '22 21:09

dfsq