angular @HostListener('window:message', ['$event']) code example
Example 1: 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 2: how to receive window.postmessage event in angular 9
receiveMessage: any = (event: any) => {
//...
}