2

In controllerA I am writing a promise to get executed and have the app move to the next view. However, the app is not dependent on the promise response in order to move to the next view. When the app moves onto the next controller, will the results of the promise still be processed from controllerA?

Example in controllerA:

doService.all().then(function(response) {
  // process response
  // could take 3 or 4 seconds to get results
}, function(error) {
  // process error
}) ;

$state.go("tab.map") ;
//move to new controller regardless of doService response or completion.
//but will doService promise still get processed?
georgeawg
  • 48,608
  • 13
  • 72
  • 95
rolinger
  • 2,787
  • 1
  • 31
  • 53
  • 2
    Yes, the promise(s) will still resolve. [Here is an example](https://stackoverflow.com/questions/24440177/angularjs-how-to-cancel-resource-promise-when-switching-routes) of a strategy to allow you to cancel a promise, but it uses the classic [deferred antipattern](https://stackoverflow.com/questions/23803743/what-is-the-explicit-promise-construction-antipattern-and-how-do-i-avoid-it). – Lex Jul 17 '19 at 21:22
  • 1
    Yes, the async operations will continue until the promises are either resolved or rejected. Is that all you are asking? – georgeawg Jul 18 '19 at 00:52
  • @georgeawg - yes, thats what I am asking. Thanks. The promise data is important but not imperative for app functionality. Goal is initiate promise, allow app to move onto new controller, and process promise results whenever they come back. I just needed to make certain that changing controllers wouldn't somehow ax or interrupt the promise from completing. Thanks. – rolinger Jul 18 '19 at 12:42
  • Yes, and Angularjs doesnt give any decent way to deal with it... You can cancel these requests on component destroy, but that requires non-fancy code. Also notice that when component is destroyed it will still call factory methods, but not component callbacks. – Petr Averyanov Jul 18 '19 at 12:56

0 Answers0