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

onEnter function arguments must be '$transition$' and '$state$' if used in state definition #573

Open
Fangfanghao opened this issue Jan 10, 2022 · 2 comments

Comments

@Fangfanghao
Copy link

Fangfanghao commented Jan 10, 2022

I put 'onEnter' in the state definition and register the state by 'UIRouter.stateRegistry.register(state)'.

We can try this in the 'react-hybrid/example/src/index.js'.
This won't work:
{
name: 'react', url: '/react', component: ReactComponent,
onEnter: (trans, state) => {
console.log(state.name);
}
},
index.js:1 Error: [$injector:unpr] Unknown provider: transProvider <- trans
(It seems like the code will put assume it's a provider named by 'argument+Provider').

This will work:
onEnter: ($transition$, $state$) => {
},

This issue only happens in 'react-hybrid', not in 'ui-router/react'.

@Fangfanghao
Copy link
Author

Is this a bug? Does anyone know the reason?

@Fangfanghao
Copy link
Author

This is a workaround. Do it the angular way: inject the provider.
onEnter: ['$transition$', '$state$', (trans, state) => {
console.log(state.name);
}],

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

No branches or pull requests

1 participant