How to limit subscribe to just one loop

Asked

Viewed 40 times

0

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);
    });
 }

However it displays Alert several times, but it displays the first one correctly, can I display only the first subscribe? value and ignore the rest? giving Alert only once inside the subscribe

1 answer

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.