AngularJS: how to use ng-idle

My current scenario:

myApp.config(['$routeProvider', function ($routeProvider)
{
    $routeProvider.when('/home', {templateUrl: 'partials/home.html', controller: 'homeCtrl'});
}

this is my curernt .config()how can i integrate the following code into my correct 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 am new to angularJS. PS ask a question to encourage me to ask questions here.

+4
source share
1 answer

Like @Pankaj, you can add ng-idle as a script dependency, load the 'ngIdle' module and add the configuration to your application.

var myApp = angular.module("myApp",['ngIdle']);

Have a look at your modified Plunker link: http://plnkr.co/edit/DWKdi0QsWdrO4jqlRP6l?p=preview

+4
source

Source: https://habr.com/ru/post/1622414/


All Articles