My current scenario is:
myApp.config(['$routeProvider', function ($routeProvider)
{
$routeProvider.when('/home', {templateUrl: 'partials/home.html', controller: 'homeCtrl'});
}
this is my curernt .config()
how can i integrate bellow code to my uper code:
.config(function(IdleProvider, KeepaliveProvider) {
IdleProvider.idle(10*60); // 10 minutes idle
IdleProvider.timeout(30); // after 30 seconds idle, time the user out
KeepaliveProvider.interval(5*60); // 5 minute keep-alive ping
})
.run(function($rootScope) {
$rootScope.$on('IdleTimeout', function() {
// end their session and redirect to login
});
});
I'm newbie in angularJS. P.S thumbup the question to encourage me to ask questions here.
The ng-idle is the module, which is required to respond to and handle the idle users in the module. The ng-idle directive displays a warning dialog by using the $uibModal from UI Bootstrap. It will do the countdown for the remaining time until the session gets timed out.
What is @ng-idle/keepalive? Module that works with @ng-idle/core to keep a user session alive while user is active.
Since AppComponent is the main/bootstrap component in the Angular application, we need to implement this logic in it. We are setting the Idle time 5 seconds which means we will get a warning message after 5 seconds of inactivity and timeout as 5 seconds which means it will be timed out within another 5 seconds.
Install bn-ng-idle Session Timeout NPM package The bn-ng-idle package exports a singleton service BnNgIdleService which is written in RxJS to listen for various DOM elements, Import the service in your module and add it to your providers array.
Like @Pankaj said, you can add ng-idle as a script dependency, load the module 'ngIdle' and add the config to your application.
var myApp = angular.module("myApp",['ngIdle']);
Have a look at your modified Plunker link: http://plnkr.co/edit/DWKdi0QsWdrO4jqlRP6l?p=preview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With