问题
So I'm working on a Angularjs based mobile app. When a user taps on each of the tabs along the bottom a new route is called which is loading the partial and controller.
In my controllers I often then request data from the server via Angularjs $resource such as
$rootScope.getPage = pageApi.query(); // GET
$rootScope.getPage = $rootScope.getPage.$promise.then(function(data) {
//Do stuff with the returned data
});
I'm using root scope here because I have a spinning loader located outside of the controllers own $scope. While waiting for the response I'm using an Angular directive (Angular Busy) to display a loader.
However as the user moves through the pages on the app, more and more promises are started (that, for example, might not be resolved as the connection has been lost).
How can I resolve / reject any other promises so that only the most recently loaded controller is waiting on a promise ?
All comments / answers are really appreciated!
Thanks, Mac
来源:https://stackoverflow.com/questions/24352236/reject-angularjs-resource-promises