I'm using ui-router 1.0.0-alpha.3. Old events are deprecated there.
so I'm trying to convert
$rootScope.$on('$stateChangeStart', (event, toState) => {
//...
});
to new way of doing things with $transitions.onStart hook -
$transitions.onStart( {}, function($state, $transition$) {
//...
});
where could I get toState param in this case?
$transitions.onStart({}, function(transition) {
console.log(transition.params('to').paramname)
})
Use $transition$.$to() for it.
$transitions.onStart( {}, function($transition$) {
// stateTo === $transition$.$to();
// Check $transition$.$to().name for state name
});
Follow documents, check Class Transition Methods, toState
in old version equal $to()
in new version
$scope.$on('$stateChangeSuccess', function(evt, toState, toStateParams, fromState) {
var oldToState = toState;
}
$transitions.onSuccess({}, function($transitions){
var newToState = $transitions.$to();
}
From Interface HookMatchCriteria:
This object is used to configure whether or not a Transition Hook is invoked for a particular transition, based on the Transition's "to state" and "from state".
Hope this help!
$transitions.onSuccess({ }, function(trans) {
stateChangeSuccessCallBack(**trans.$to().self**, trans.params('to'));
});
trans.$to().self This gives the exact object as in $stateChangeSuccess(event, **toState**)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With