window.postmessage in angular code example

Example 1: how to receive window.postmessage event in angular 9

receiveMessage: any = (event: any) =>  {
  //...
}

Example 2: how to receive window.postmessage event in angular 9

constructor(private _authService: AuthService, private _router: Router) { 
   if (window.addEventListener) {
     window.addEventListener("message", this.receiveMessage.bind(this), false);
   } else {
      (<any>window).attachEvent("onmessage", this.receiveMessage.bind(this));
   }
}

Example 3: how to receive window.postmessage event in angular 9

window.addEventListener("message", () => {
   this.receiveMessage();
}, false)