2017-05-31 45 views
3

我編寫了一個指令,用於監視$locationChangeStart事件,並在窗體未保存更改時向用戶顯示消息。問題是事件處理程序從不觸發。這裏是notify-on-location-change.js如何在用戶離開時不顯示保存更改的警告消息

(function() { 
    'use strict'; 


    angular.module('myApp.directives').directive('notifyOnLocationChange', ['$scope', 'event', 'next', 'current', function ($scope, event, next, current) { 

     $scope.$on('$locationChangeStart', function() {     
      if (true) { 
       alert('Unsaved data!'); 
      }     

     }); 

     $scope.$on('$stateChangeStart', function() {     
      if (true) { 
       alert('Unsaved data!'); 
      }     

     }); 


    }]); 

})(); 

那麼我標記的形式我想觸發警告我的代碼的簡化版本:

<form name="detailsForm" ng-submit="$ctrl.onSubmit()" novalidate notifyOnLocationChange> 

notify-on-location-change.js index.html中包含

我在想什麼這裏?

回答

相關問題