angularjs: preventing route changes -


i've tried doing following in controller:

  $scope.$on("$routechangestart", function (event, next, current) {        if (!confirm('are sure ?')) {          event.preventdefault();                   }   }); 

but doesn't work. not supposed way ?

i put directive on links, should confirmed before changing route. prototyped in jsfiddle, did not test it. think, should proper way.

(function (angular) {   module = angular.module('confirm', []);   confirmdirective = function () {       return {         restrict: 'a',         link: function (scope, elm, attrs, ctrls) {             angular.element(elm).bind('click', function (event) {                 alert("sure?");                 event.preventdefault();                 return false; //or true, depends on             });         }     };   };   module.directive("confirm", confirmdirective); }(angular)); 

http://jsfiddle.net/l6xbf/3/

check , try it.

regards


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -