Angular 7 - Observable subscription after reload page

1.5k Views Asked by At

Good afternoon. I'm working on solution to create a inactivity modal after the user sign in into the application. Per requirements of the project, I can't use any library or package to implement this task. The implementation that I have, works in the following way:

  1. The user sign in into the system. A backend validation occurs.
  2. If the sign in was successful, I emit a value to the inactivity modal component to notify that the timer should start.

This solution works fine, but I have a problem when the application reload any page. Since the event is only emitted when the user sign in into the app, now the inactivity modal counter doesn't start. I tried to emit the event also in the constructor of the app.component.ts but for some reason, the service doesn't trigger the method. Thanks for any help, I really appreciate it.

// 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();
      }
    });
  }
0

There are 0 best solutions below