Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: How to use ng-idle

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.

like image 381
Tech Kid Avatar asked Jan 01 '16 06:01

Tech Kid


People also ask

How to use ng idle in AngularJS?

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?

What is @ng-idle/keepalive? Module that works with @ng-idle/core to keep a user session alive while user is active.

How will you implement session idle and session timeout in angular application?

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.

How do you implement idle timeout in angular 8?

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.


1 Answers

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

like image 133
Chanthu Avatar answered Sep 27 '22 20:09

Chanthu