I need to display an alert every time my main component changes route, so I created the following script in my AppComponent
:
constructor(private router: Router) {
router.events.subscribe((val) => {
alert(val);
});
}
But it displays the alert several times, but it displays the first correctly, how can I display only the first value of the subscribe, and ignore the rest? giving the alert just once inside the subscribe