I am currently developing an idle timeout feature for my application. Once the system detects inactivity, a modal window is triggered. Within this modal window, a timer is presented to the user. My goal is to have a way to determine when this timer reaches 0, so I can proceed with signing off the user accordingly.
export class IdleModalComponent implements OnInit {
counter$: Observable<number>;
count = 300 // Here we set a countdown of 5 minutes before implementing the inactivity logic
constructor(public dialogRef: MatDialogRef<IdleModalComponent>) {
this.counter$ = timer(0, 1000).pipe(
take(this.count),
map(() => (--this.count)),
);
}
}
By binding the counter observable in the HTML, the countdown is accurately displayed. The key requirement now is to identify:
this.count === 0
.