Search code examples
angulartypescriptwindowlocation

How to use @HostListener when location.hash changed? (angular 2)


I am trying to call some function every time, when url changes.

@HostListener('window:hashchanged', ['$event'])
  someFunction(event) {
  console.log('test')
}

How i can do this?


Solution

  • The event is hashchange withaout the d at the end:

    @HostListener('window:hashchange', ['$event'])