I just replaced the $stateChangeStart
with $transitions.onStart
$rootScope.$on('$stateChangeStart', function(e, ...){
e.preventDefault();
// other code goes here...
});
to
$transitions.onStart({}, function(tras){
// need a code equivalent to e.preventDefault
// need a code to identify event.defaultPrevented
// other code goes here...
// get parent states
_o.util.getAncestorStates(toState.name, true).reverse()
.forEach(function (state) {
// certain condition to call event.preventDefault()
if(event.defaultPrevented) {....}
});
});
and I guess, we can prevent the transition by adding return $q.reject()
instead of e.preventDefault()
but I could not understand how the code below return $q.reject()
would execute.
Also, how can I replace event.defaultPrevented
?
I think should be done something on the transition.promise
but not clear.
I am sorry, I can't understand the official doc - https://ui-router.github.io/ng1/docs/latest/ easily. Can anybody help me finding out a better explanation or the replacement for the above code?
return false
from.onStart
to cancel the transition.. – Rubricianevent.defaultPrevented
- I process all parent states & on a certain condition I callevent.preventDefault
& I checkevent.defaultPrevented
for any other parent state. – Townsville.then
blocks are skipped if a previous block cancels. AnonStart
handler will never be called if a previous handler cancels a transition.event.defaultPrevented
will never betrue
in anonStart
handler. Instead theonError
handler chain gets called and those blocks will only be called if and only ifevent.defaultPrevented
is true. – Rheims