user3140824
user3140824

Reputation: 370

How to detect fragment change?

I need to identify when an anchor is changed and so call a function

Where I set the fragment:

  changeFragment(id) {
    this.router.navigate([], { fragment: id });
  }

Any help is welcome, thanks

Upvotes: 5

Views: 2195

Answers (1)

Chellappan வ
Chellappan வ

Reputation: 27293

Inject ActivatedRoute service in construtor, Then use fragement method in Activatedroute to listen fragement changes

Try this:

 this.route.fragment.subscribe( fragment =>{
      console.log(fragment);
 })

Upvotes: 7

Related Questions