2

I am using ng-idle to detect inactivity.

The idleDuration is set like so:

.config(function($idleProvider, $keepaliveProvider) {
            // configure $idle settings
            $idleProvider.idleDuration(5); // in seconds
            $idleProvider.warningDuration(5); // in seconds
            $keepaliveProvider.interval(2); // in seconds
        })

How can I change it at runtime in a controller or in a service?

It is possible to inject the $idle service like so:

.controller('EventsCtrl', function($scope, $idle)

Unforunately $idle does not have a property for changing the idleDuration.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
user2939415
  • 864
  • 1
  • 11
  • 22

2 Answers2

1

As per v1.0.0, Idle.setIdle() can change the configuration value at any time.

moribvndvs
  • 42,191
  • 11
  • 135
  • 149
1

I know i'm answering late...

In older versions v1.0.0 Idle time cannot be change at the run-time, once it is initialized using IdleProvider.idle(seconds).

But in version v1.0.0 he provided new api to change config value at rum-time using Idle.setIdle(seconds)

Note: Seconds should be integer value. By default Idle time will be 20 mins

Refernce https://github.com/HackedByChinese/ng-idle/wiki/Idle-and-Idleprovider

Pradeep
  • 2,530
  • 26
  • 37