Prompt leaks not being fixed in AngularUI Router?

I am using an angular UI router, and I was wondering if anyone would be able to find out whether or not unresolved promises when using resolve leaks. Our use case is that in some states we needed to perform some checks and then go to another URL before the initial state loads.

The way we did this was checking and switching the URL using $location inside resolve and leaving an unresolved promise. An unresolved promise was used to prevent the loading of the original state controllers and templates (otherwise they would have wandered errors).

So my question is, does this practice cause the escape from unresolved leak promises? I understand that an alternative is to set a long $timeout to resolve promises, but if it is not needed, I would like to avoid it.

+3
source share
1 answer

You will need to decide or reject the promise. I would suggest that the URL switch will occur in the $stateChangeError event $stateChangeError , which will be fired by dropping the promise. You can pass the location you want to go to reject([data]) to the listener.

http://fiddle.jshell.net/L9jxf/2/

Some promise that they will deviate after a timeout (simulates a server call)

  protected: ['$timeout', '$q', function ($timeout, $q) { var deferred = $q.defer(); $timeout(function () { deferred.reject({type:'redirect',location:'401'}); }, 1000); return deferred.promise; }] 

This refers to failure

 app.run(function ($rootScope, $state) { $rootScope.$on('$stateChangeError', function (e, to, toParams, from, fromParams, error) { if (error.type === 'redirect') { $state.transitionTo(error.location); } }); }); 
+8
source

Source: https://habr.com/ru/post/975169/


All Articles