Angular | how to call a ngonit() method from another component

578 Views Asked by At

Here the scenario is that i have a header component where i have a selection box . on change of that selection i have to refresh the current page

example:

this seems not working for me

this.router.navigate([ document.location.pathname]);
1

There are 1 best solutions below

2
On BEST ANSWER

Refreshing the actual page is probably not what you want. I assume you just want to reload the data based on that selection. How do you know what is selected in the 1st place?

You should be using a common service that:

  • selection box from header, on change, notifies that service that the selection changed
  • whatever component cares, subscribes to the event exposed by that service and does whatever it wants with it (reload/etc.)