When a user tries to click browser back button and dere is dirty data on the form, it shows a confirmation.
Here is the angular js controller code
function MyCtrl2($rootScope, $location, $scope) {
$rootScope.$watch(function () {
return $location.path();
},
function (newValue, oldValue) {
if ($scope.myForm.$dirty) {
var a = confirm('do you');
if (!a) {
//how to prevent this redirect
}
}
},
true);
}
MyCtrl2.$inject = ['$rootScope', '$location', '$scope'];
But how to prevent the redirect on
FYI canceling a route is now possible in Angular.
$scope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {
event.preventDefault();
});
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