下午好。我正在研究在用户登录应用程序后创建非活动模式的解决方案。根据项目的要求,我不能使用任何库或包来实现这个任务。我拥有的实现按以下方式工作:
- 用户登录系统。发生后端验证。
- 如果登录成功,我会向非活动模式组件发出一个值,以通知计时器应该启动。
此解决方案工作正常,但是当应用程序重新加载任何页面时出现问题。由于该事件仅在用户登录应用程序时发出,因此现在不活动模式计数器不会启动。我也尝试在 app.component.ts 的构造函数中发出事件,但由于某种原因,服务不会触发该方法。感谢您的帮助,我真的很感激。
// timer.service.ts
@Output() startTimerModalEvent: EventEmitter<boolean> = new EventEmitter();
startTimer() {
this.startTimerModalEvent.emit(true);
}
// inactivity-modal.component.ts
constructor(
private timeLeftSrv: TimeLeftService
) {
timeLeftSrv.startTimerModalEvent.subscribe(res => {
if (res) {
this.startTemp();
}
});
}