moribvndvs / ng2-idle

Responding to idle users in Angular (not AngularJS) applications.
https://moribvndvs.github.io/ng2-idle
Apache License 2.0
323 stars 129 forks source link

documentation #2

Closed david-gang closed 8 years ago

david-gang commented 8 years ago

Hi,

It would be great to have a code snippet to see how to use the Idle service.

Thanks, David

moribvndvs commented 8 years ago

Indeed, sorry. I was a little gunshy about putting one together with Angular state being in a beta flux. Oddly enough, there is an example in the README for the ng2-idle-keepalive plugin for ng2-idle. I'll refresh with the latest Angular beta and add a sample.

paullryan commented 8 years ago

So on that note, what am I doing wrong with

      idle.setIdle(5);
      idle.setTimeout(5);
      idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
      idle.onIdleStart.subscribe(response => {
        console.log('idling');
        console.log(response);
      });
      idle.onIdleEnd.subscribe(response => {
        console.log('idle ended');
        console.log(response);
      });
      idle.onTimeout.subscribe(response => {
        console.log('timed out');
      });

seems like the correct direction based on your source but none of my subscribes are triggering. If I figure it out before you get back on I'll try to update here.

BahKoo commented 8 years ago

I think you need to call idle.watch() to get it started.