2015-09-03 3 views

ответ

1

Я действительно мало знаю о angularjs, я делаю курс по нему, но я только начинаю. Хотя я знаю кого-то из github, который мог вам помочь. Я только что включены отрывки, но вы должны проверить этот сайт, если вы хотите узнать больше: https://github.com/HackedByChinese/ng-idle

Во всяком случае, здесь:

Включите угловой idle.js после angular.js. Вы можете установить с помощью Bower с помощью этой команды: bower install --save ng-idle.

Голых кости Пример:

// include the `ngIdle` module 
var app = angular.module('demo', ['ngIdle']); 

app 
.controller('EventsCtrl', function($scope, Idle) { 
    $scope.events = []; 

    $scope.$on('IdleStart', function() { 
     // the user appears to have gone idle 
    }); 

    $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.$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.$on('Keepalive', function() { 
     // do something to keep the user's session alive 
    }); 

}) 
.config(function(IdleProvider, KeepaliveProvider) { 
    // configure Idle settings 
    IdleProvider.idle(5); // in seconds 
    IdleProvider.timeout(5); // in seconds 
    KeepaliveProvider.interval(2); // in seconds 
}) 
.run(function(Idle){ 
    // start watching when the app runs. also starts the Keepalive service  by default. 
    Idle.watch(); 
}); 

Надеется, что помогло :)

+0

Спасибо за ответ! это действительно полезно. Одна вещь, которая не работает в моем случае: после окончания сеанса имя браузера «Срок действия вашей сессии истек». Но после входа в систему и это имя не меняется, оно показывает, что ваш сеанс истек. – user1457957

+0

ng-idle отлично работает для первого таймаута. После истечения срока, Затем мы снова заходим в приложение, после чего оно не работает. Есть идеи? – user1457957

+0

Получил! Необходимо вызвать Idle.watch() после входа в систему, чтобы снова активировать простоя. – user1457957

Смежные вопросы