我正在尝试在登录控件中写入空闲超时问题,但是却无法读取未定义的属性'watch'。
我正在尝试在Tomcat Server 7和Angular 1.5中执行以下代码
$scope.started = false;
function closeModals() {
alert(1);
if ($scope.warning) {
$scope.warning.close();
$scope.warning = null;
}
if ($scope.timedout) {
$scope.timedout.close();
$scope.timedout = null;
}
}
$scope.$on('IdleStart', function() {
closeModals();
$scope.warning = $modal.open({
templateUrl: 'warning-dialog.html',
windowClass: 'modal-warning'
});
});
$scope.$on('IdleEnd', function() {
closeModals();
});
$scope.$on('IdleTimeout', function() {
closeModals();
$scope.timedout = $modal.open({
templateUrl: 'timedout-dialog.html',
windowClass: 'modal-danger'
});
});
$scope.start = function() {
console.log('start');
closeModals();
Idle.watch();
$scope.started = true;
alert("Hi")
};
$scope.stop = function() {
console.log('stop');
closeModals();
Idle.unwatch();
$scope.started = false;
};
nuncasApp.config(function(IdleProvider, KeepaliveProvider) {
alert(3);
IdleProvider.idle(5);
IdleProvider.timeout(5);
KeepaliveProvider.interval(10);
IdleProvider.interrupt('keydown wheel mousedown touchstart touchmove scroll');
});
我从https://jsfiddle.net/esoyke/fkqLqy7c/获得了代码。
我收到以下错误:
angular.js:13920 TypeError: Cannot read property 'watch' of undefined at b.$scope.start (loginCtrl.js:141)
at b.$scope.validateUser (loginCtrl.js:18)
at fn (eval at compile (angular.js:14817), <anonymous>:2:227) at b (angular.js:15906)
at e (angular.js:25885)
at b.$eval (angular.js:17682)
at b.$apply (angular.js:17782)
at HTMLButtonElement.<anonymous> (angular.js:25890)
at Sf (angular.js:3497)
at HTMLButtonElement.d (angular.js:3485)
答案 0 :(得分:0)
请确认您已正确注入此依赖项,如var myApp = angular.module("myApp", ['ngIdle'])
和app.controller('DemoCtrl', function($scope, Idle /*other injections*/)
中一样。