Reputation: 757
in the official doc :
https://ui-router.github.io/docs/latest/modules/ng1.html , in the example :
MyController.$inject = ['$transition$'];
function MyController($transition$) {
var username = $transition$.params().username;
// .. do something with username
}
$transition$ is injected in the controller, but when I do the same with angular 1.6.1 and ui-router 1.0.0-beta.3 I have the follwing error, using a component architecture: Error: [$injector:unpr] Unknown provider: $transition$Provider
I am able to inject $transition$ only in a resolve.
Upvotes: 3
Views: 2367
Reputation: 185
$transition$
isn't a global service
, it's a locally scoped injectable
.
https://github.com/angular-ui/ui-router/issues/3110
You can use component input bindings to address this:
.component('adminApplicants',{
bindings: { $transition$: '<' },
templateUrl:'admin.applicants.html',
controller:function($http,$transition$){
}
})
Upvotes: 0
Reputation: 10569
From the ui-router Route to Component guide:
When routing to a legacy style template/controller (not routing to components), the transition could be injected as $transition$.
...
To access the Transition on a routed component, you should bind to $transition$ in your component.
As you noted, therefore this can only be accessed via the resolve when routing to components. This is because the $transition$
service is a locally scoped injectable which is not available for components. More information can be found in issue ui-router#3110
Upvotes: 1
Reputation: 53
You are trying to inject the '$transition$' object where you should be injecting the '$transitions' service into your controller. See the distinction in the documentation on this page:
https://ui-router.github.io/ng1/docs/latest/modules/injectables.html#transition
Upvotes: 1