Angularjs how to cancel resource promise when switching routes

后端 未结 5 1883
孤街浪徒
孤街浪徒 2020-11-30 05:00

I\'m just getting my feet wet with Angularjs. I have an issue which I think has something to do with promises.

Let\'s say I load route \'A\' which makes several ajax

5条回答
  •  迷失自我
    2020-11-30 05:12

    There is a similar question with the answer "How to cancel $resource requests".

    While it does not address the question exactly it gives all ingredients to cancel resource request when route is switched:

    
    
    
      
      Cancel resource
      
      
      
    
    
      

    How it works

    1. $resource merges action definition, request params and data to build a config parameter for an $http request.
    2. a config parameter passed into an $http request is treated as a promise like object, so it may contain then function to initialize config.
    3. action's then function may pass timeout promise from params into the config.

    Please look at "Cancel Angularjs resource request" for details.

提交回复
热议问题