Gyuzal R Gyuzal R - 10 months ago 42
Javascript Question

AngularJS - Detect no action for n minutes and go to default state

I am new to Angular and would appreciate your advice. I'm using

and I configured states like this:

app.config(function($stateProvider, $urlRouterProvider) {
.state('category', {
url: '/category',
templateUrl: 'category.html',
controller: 'categoryController as catCtrl',
reload: true
.state('category.categoryDetail', {
templateUrl: 'categoryDetail.html',
controller: 'categoryDetailController as catDetailCtrl',

.state('category.categoryDetail.product', {
templateUrl: 'product.html',
controller: 'productController as productCtrl'

I need to set timeout function that checks if there is no action for 'n' minutes, then I need the website to return to the default state
. I know I could do it with
but I'm not sure where to embed the code.


You may use .

I made an example of what you need in plunker:

Copy the code and try it locally, it will work fine.

I used this answer: auto logout with angularjs based on idle user