angularJS でアイドル タイムアウトの種類の処理を許可する唯一の方法は、HackedByChinese によって作成されたng-idleと呼ばれるこのカスタム ディレクティブを使用することです。このディレクティブの使用に関する問題は、タイムアウト後にユーザーをサインアウトしようとしても何も起こらないことです。
ng-show
ユーザーがアイドル状態かどうかを検出する限り、意図したとおりに機能しますが、ユーザーがタイムアウト状態に達すると、何も起こりません。
ここに私のJSがあります:
// include the `ngIdle` module
var app = angular.module('demo', ['ngIdle', 'ui.bootstrap']);
app
.controller('EventsCtrl', function($scope, Idle, $modal) {
$scope.logIn = function(){
$scope.loggedIn = true;
Idle.watch();
};
$scope.events = [];
$scope.$on('IdleStart', function() {
closeModals();
$scope.amIdle = true;
});
$scope.$on('IdleWarn', function(e, countdown) {
// follows after the IdleStart event, but includes a countdown until the user is considered timed out
// the countdown arg is the number of seconds remaining until then.
// you can change the title or display a warning dialog from here.
// you can let them resume their session by calling Idle.watch()
});
$scope.$on('IdleTimeout', function() {
// the user has timed out (meaning idleDuration + timeout has passed without any activity)
// this is where you'd log them
$scope.loggedIn = false;
$scope.amIdle = false;
});
$scope.$on('IdleEnd', function() {
// the user has come back from AFK and is doing stuff. if you are warning them, you can use this to hide the dialog
$scope.amIdle = false;
});
/*$scope.$on('Keepalive', function() {
$scope.amIdle = false;
});*/
})
.config(function(IdleProvider, KeepaliveProvider) {
// configure Idle settings
IdleProvider.idle(5); // in seconds
IdleProvider.timeout(5); // in seconds
KeepaliveProvider.interval(1); // in seconds
})
そして私のHTML:
<!DOCTYPE html>
<html lang="en-us" ng-app="demo">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="angular-idle.js"></script>
<script src="app.js"></script>
<script src="ui-bootstrap-tpls-0.13.0.min.js"></script>
<body ng-controller="EventsCtrl">
<div ng-show="!loggedIn">
<label>Log In:<input type="text" name = "user">
<button type = "submit" ng-click="logIn()">Submit</button>
</label>
</div>
<div ng-show="loggedIn"><h2>NG-Idle test</h2>
<center><div ng-show="amIdle">Yo wake up</div>
</div>
</body>
</html>