3

In my angular application I have to opened a new window and dispatched an event back to the controller .The code is working on Chrome and Firefox but it does not work for Edge

Below is the code from the external file

try {
   var ev = new Event('abc');
   ev['data'] = model;
   window.opener.dispatchEvent(ev);
} catch (e) {
    alert(e);
}

In the external window i get the alert ERROR:invalid argument.

in the angular component i have the listener

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

Couldn't get much info from other answers.

Please Guide Thanks

Ramesh
  • 2,297
  • 2
  • 20
  • 42
Shruti Nair
  • 1,982
  • 8
  • 30
  • 57

1 Answers1

0

The issue was not with the disptachEvent.It was because the child window was losing the scope of the parent angular component from which it was opened. To solve this i found the solution from this thread.

Before opening the child window we must set the reference of angularComponentRef

window['angularComponentRef'] = {component: this, zone: _ngZone};
Shruti Nair
  • 1,982
  • 8
  • 30
  • 57