angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.56k stars 3.01k forks source link

Resolvable async .get() not complete for onExit hook #3748

Closed adamreisnz closed 4 years ago

adamreisnz commented 5 years ago

This is a (check one box):

My version of UI-Router is:

"@uirouter/angularjs": "^1.0.20", "@uirouter/core": "^5.0.21",

Bug Report

I'm getting a Resolvable async .get() not complete error when trying to obtain a resolved value in an onExit hook. This strikes me as odd, as the route has already been resolved, and the resolvables are all there. So why are they not available in an onExit hook?

E.g:

$transitions.onExit({exiting: 'foo'}, transition => {
    const user = transition.injector().get('user'); //errors
});

Expected Behavior:

To have all the resolvables of the state available in the onExit hook.

Link to Plunker or stackblitz that reproduces the issue:

http://plnkr.co/edit/KOClmTCu8ajm5BYP93uM

From playing around with it in Plunkr, it appears that the onExit hook is actually trying to get resolvables for the new state. How can I get the resolvables for the state I'm exiting?

I need access to them to do some cleanup.

christopherthielen commented 5 years ago

you can access the resolves from an exiting state by getting the injector for the "from" path path:

.onExit({ exiting: 'foo.bar' }, trans => {
  // Gets the resolve value of `myResolve` from the state being exited
  var fooData = trans.injector(null, 'from').get('myResolve');
});

See: https://ui-router.github.io/ng1/docs/latest/classes/transition.transition-1.html#injector

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues may be reopened.

Thank you for your contributions.