I have an Angular component that displays data and includes a button called "Go to Dashboard". I want to implement a feature where the user can either click on this button to navigate to the dashboard or have the application automatically redirect them after 10 seconds if they do not click on the button.
If the user does click on the "Go to Dashboard" button, another timer is set for 10 seconds to either refresh the page or return to the dashboard link.
I attempted to handle this using a variable called isClickGoToDashboard, but it seems to keep calling the function again, especially after the initial load in ngOnInit().
How can I prevent the counter from resetting and the function from being called again after clicking the button?
ngOnInit(): void {
if (!this.isClickGoToDashboard) {
setTimeout(() => {
this.router.navigateByUrl('home');
}, 10000);
}
}
goToDashboard() {
this.isClickGoToDashboard = true;
this.router.navigateByUrl('home');
}