Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.0-beta.1 onEnter/onExit no longer injectable? #2863

Closed
orneryd opened this issue Jul 8, 2016 · 1 comment
Closed

1.0.0-beta.1 onEnter/onExit no longer injectable? #2863

orneryd opened this issue Jul 8, 2016 · 1 comment

Comments

@orneryd
Copy link

orneryd commented Jul 8, 2016

I would suggest that this change be reverted and allow dependencies to be injected into the onEnter/onExit hooks.

This allows services such as the $modal service from foundation/bootstrap to open/close modals based on states instead of managing that inside of a controller. it allows for much more dynamic behavior of states.

@christopherthielen
Copy link
Contributor

christopherthielen commented Jul 9, 2016

Angular 1 only: onEnter/onExit on a state declaration is still injected, as before.

See the Note on the bottom of breaking change #2 in the release notes: https://github.com/angular-ui/ui-router/releases/1.0.0-beta.1

What this means is that this is still injected:

.state('foo', {
  onEnter: [ '$modal', function($modal) { ... } ]
});

While this hook (not declared on a state declaration) is not injected:

$transtionsProvider.onExit({ exiting: 'mystate' }, function($modal) { ... });

Instead, the first parameter for hooks is the current Transition object, which you can get the injector() from. see docs https://ui-router.github.io/docs/latest/classes/transition.transition-1.html#injector

So for global onEnter/onExit hooks not declared on the state, you do something like so:

$transtionsProvider.onExit({ exiting: 'mystate' }, function(trans) { 
  var $modal = trans.injector().get('$modal') ... 
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants