Recently, I made a change in my code where I replaced $stateChangeStart
with $transitions.onStart
$rootScope.$on('$stateChangeStart', function(e, ...){
e.preventDefault();
// other code goes here...
});
Now, the updated code looks like this:
$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) {....}
});
});
I believe, we can prevent the transition by using return $q.reject()
instead of e.preventDefault()
, but I am not sure how exactly the code below return $q.reject()
will be executed.
Furthermore, I am curious about how to replace event.defaultPrevented
.
I suspect that something needs to be done with transition.promise
, but the process is not clear to me.
Unfortunately, understanding the information in the official documentation at seems challenging for me. Can anyone provide a clearer explanation or suggest an alternative solution for the mentioned code?