Although it may seem simple, I am new to angularjs. Here is the code for my angularjs controller:
function MyCtrl1($scope, $location, $rootScope) {
$scope.$on('$locationChangeStart', function (event, next, current) {
event.preventDefault();
var answer = confirm("Are you sure you want to leave this page?");
if (answer) {
}
});
}
MyCtrl1.$inject = ['$scope', '$location', '$rootScope'];
The next
variable contains the URL to redirect to upon confirmation.OK. How can I achieve this in angularjs?