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

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -