ng-idle
ng-idle copied to clipboard
Common module across entire application for ngidle
I defined a module that has code to set the "Idle" configure parameters and start the watch process. I am including this module as a dependency in one of the module of my application. I see that none of the events like (IdleStart, IdleEnd, etc) are called.
When I set the "Idle" configuration and run parameters directly on my application module, it works fine.
Rather than having to do "Idle" configuration and run parameters for each of the modules, I would like to define the configuration and run parameters for a common module and include the common module as a dependency in all the modules where I want the session timeout feature to apply.
Am I missing something ?
Following is my common module code :
var app = angular.module('app.session', ['ui.bootstrap','ngIdle']); app.controller('AppSession', ['$scope', '$rootScope', '$uibModalInstance','Idle', function ($scope, $rootScope, $uibModalInstance,Idle) { $scope.$on('IdleStart', function () { // the user appears to have gone idle console.log("In IdleStart); });
$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
console.log("In IdleTimeout);
});
$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
console.log("Entered IdleEnd");
});
$scope.$on('IdleStart', 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
console.log("Entered IdleStart");
});
$scope.$on('Keepalive', function () {
console.log("Entered keepalive");
});
}]);
app.config(['IdleProvider', 'KeepaliveProvider', function (IdleProvider, KeepaliveProvider) {
// configure Idle settings
IdleProvider.idle(35); // in seconds
IdleProvider.timeout(30); // in seconds
}])
app.run(['Idle', function (Idle) {
// start watching when the app runs. also starts the Keepalive service by default.
Idle.watch();
}]);