How can we use $transitions
to cancel a state change to prompt the user for saving? Previous ui-router versions used to have an event
in the callback, and could be stopped with event.preventDefault()
, but this event seems to have disappeared.
I'm using this code in my controller:
var onTransitionStartOff = $transitions.onStart({}, function($transitions)
{
if ($scope.itemTracker.hasChanged()) {
$scope.itemTracker.askExitConfirm().then(function () {
onTransitionStartOff();
var toState = $transitions.$to();
$state.go(toState);
}, function () {});
return $q.reject(null);
}
onTransitionStartOff();
});
It works great, but it leaves an error message in the console due to the rejected promise.
I took a look in stateService.ts, but I didn't see some interesting things...