angularjs - Warn user before navigating to a different view -
I want to warn the user and before that the user navigates from some pages in their application, like a new one Message view
If you can say a link or button to navigate to another route or state , You can easily show a model that verifies navigation:
& lt; A href = "" ng-click = "goToAnotherState ()" & gt; Go .. & Lt; / A & gt; $ Scope.goToAnotherState = function () {// show modal and confirm if your choice is (modalResponse.Ok) {$ state.go ('anotherstate'); }}
Another option would be to do this in the $ locationChangeStart
event of the UI-router, but if you are looking at it only here , The first approach is better $ locationChangeStart
approach:
$ rootScope $ ('$ LocationChangeStart', function (event, next, previous) {event.preventDefault (); // Show Modal if (modalResponse.ok) {var destination = next. Substr (next.indexOf ('#') + 1, next.length) .trim (); $ location.path (destination)}}
Comments
Post a Comment