我正在使用 Angular 创建项目。在我的项目中,我使用了库 ngIdle,当系统空闲时,它会给出带有计时器的弹出窗口,之后用户将从系统中注销。
当浏览器进入睡眠状态时,这个问题会出现,然后计时器正在恢复。
https://moribvndvs.github.io/ng2-idle/
这是代码:
idle.setIdle(5);
// sets a timeout period of 5 seconds. after 10 seconds of inactivity, the user will be considered timed out.
idle.setTimeout(60);
// sets the default interrupts, in this case, things like clicks, scrolls, touches to the document
idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
idle.onIdleEnd.subscribe(() => this.idleState = 'No longer idle.');
idle.onTimeout.subscribe(() => {
this.idleState = 'Timed out!';
this.timedOut = true;
});
idle.onIdleStart.subscribe(() => this.idleState = 'You\'ve gone idle!');
idle.onTimeoutWarning.subscribe((countdown) => {
this.idleState = 'You will time out in ' + countdown + ' seconds!'
console.log(this.idleState)
}
);
// sets the ping interval to 15 seconds
keepAlive.interval(15);
keepAlive.onPing.subscribe(() => this.lastPing = new Date());
this.reset();
reset() {
// this.idle.setTimeout(false);
this.idle.watch();
this.idleState = 'Started.';
this.timedOut = false;
}
当我把它this.idle.setTimeout(false);
放在重置中时,计时器没有启动。