I\'m working on an eCommerce application in Angular 2 with a node and express api backend. I\'m currently working on the social login section where I am using passport-faceb
You should change the way you declare the eventListener (by using bind(this) or an anonymous function, or change the way you declare your eventHandlers:
bind(this):
constructor(private _authService: AuthService, private _router: Router) {
if (window.addEventListener) {
window.addEventListener("message", this.receiveMessage.bind(this), false);
} else {
(window).attachEvent("onmessage", this.receiveMessage.bind(this));
}
}
anonymous function
window.addEventListener("message", () => {
this.receiveMessage();
}, false)
different declaration of eventHandler
receiveMessage: any = (event: any) => {
//...
}
Take your pick :) With the last option it is easy to detach the eventListener