moribvndvs / ng2-idle

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

Idle.setIdleName('yourIdleName') #87

Open soniyaBisht04 opened 6 years ago

soniyaBisht04 commented 6 years ago

I want to create multiple instances of idle in the project. I tried using setIdleName each and every time am creating new instance, still timeout of one idle instance is triggering another timeout subscriber.

How we can actually make use of setIdleName or check which idle instance we are working on?

fetters5 commented 6 years ago

I've noticed that using setIdleName results in the appropriate creation of the new storage keys, but still created the default idling key image

Not sure if that could potentially be causing issues for you

ednjv commented 6 years ago

@soniyaBisht04 the way I figured to fix this it's to define a provider on each component that is going to declare its own ng2Idle instance. e.g

import { Idle, IdleExpiry, LocalStorageExpiry } from '@ng-idle/core';

@Component({
  providers: [LocalStorageExpiry, { provide: IdleExpiry, useExisting: LocalStorageExpiry }, Idle],
  selector: 'component-a',
  template: ''
})
export class ComponentA {
  constructor(public idle: Idle) {
    this.idle.setIdleName('idleA');
  }
}
import { Idle, IdleExpiry, LocalStorageExpiry } from '@ng-idle/core';

@Component({
  providers: [LocalStorageExpiry, { provide: IdleExpiry, useExisting: LocalStorageExpiry }, Idle],
  selector: 'component-b',
  template: ''
})
export class ComponentB {
  constructor(public idle: Idle) {
    this.idle.setIdleName('idleB');
  }
}

I hope this helps

jjlorenzo commented 6 years ago

I'm still see the ng2Idle.main.idling being created

ednjv commented 6 years ago

@jjlorenzo yeah, can't tell right now how to avoid that. What I'm doing is re-using the main idle for whatever I need, and then create another instance for something else

jjlorenzo commented 6 years ago

makes sense! thanks for confirming that