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中包含
我在想什麼這裏?