1

I'm using Angular5 and I'm not able to triggered controller method from window storage event.

In init the controller init, I declare a window storage event like this:

window.addEventListener('storage', this.messageReceive);

Now when this event is fired we are not able to hit any method of that controller, because we are on some other controller.

Can you please suggest what we need to do?

Capricorn
  • 2,061
  • 5
  • 24
  • 31
Parmod
  • 9
  • 1

1 Answers1

0

That's why angular discourages you from using window properties or directly manipulating the DOM. Your attempt is like binding a regular click-listener to a DOM object and trying to execute some component functionality.

The straight-forward solution would be to use a proper layer between the browser functionality and angular like angular-localstorage-observables or ngx-webstorage. In case you want to or have to implement that layer on your own, I would recomment to check out their github repos to inspect the source code.

Capricorn
  • 2,061
  • 5
  • 24
  • 31