2015-09-03 70 views

回答

1

我真的不瞭解很多關於angularjs的知識,我正在做一個課程,但我剛剛開始。雖然我知道github上有人可以幫助你。我剛剛列入片段在這裏,但你應該看看這個網站,如果你想知道更多:https://github.com/HackedByChinese/ng-idle

不管怎麼說,那就是:

包括angular.js后角idle.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