Reject Angularjs resource promises

…衆ロ難τιáo~ 提交于 2020-01-03 22:11:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!