I am updating / rewriting an existing angular application to use angular2. My problem is that I want to open the OAuth stream in a new popup, and once the OAuth stream has completed, use window.postMessage to contact the angular 2 application that the OAuth stream was successful.
I currently have an angular 2 service
export class ApiService { constructor(private _loggedInService: LoggedInService) { window.addEventListener('message', this.onPostMessage, false); } startOAuthFlow() { var options = 'left=100,top=10,width=400,height=500'; window.open('http://site/connect-auth', , options); } onPostMessage(event) { if(event.data.status === "200") {
This template, which is loaded at the end of the OAuth stream
<html> <head> <title>OAuth callback</title> <script> var POST_ORIGIN_URI = 'localhost:8000'; var message = {"status": "200", "jwt":"2"}; window.opener.postMessage(message, POST_ORIGIN_URI); window.close(); </script> </head> </html>
Using window.addEventListener similar seems to completely break the angular 2 application, dereference this .
So my question is: can I use window.addEventListener or not use postMessage to communicate with the angular2 application?
** Complete angular2 noob, so any help would be appreciated
royka source share