import { Component , Inject , OnInit } from '@angular/core' ; import { IPostMessageBridge , IPostMessageEventTarget , PostMessageBridgeFactory } from 'ngx-post-message/ngx-post-message' ; @ Component ( { selector : 'app-root' , templateUrl : './app.component.html' , styleUrls : [ './app.component.css' ] } ) export class AppComponent implements OnInit { title = 'app' ; constructor ( @ Inject ( PostMessageBridgeFactory ) private bridgeFactory ) { } public ngOnInit ( ) { /**
         * Root context
         */ const iFrame = window . frames [ 0 ] ; const currentWindow = window ; const bridge = this . bridgeFactory . makeInstance ( ) . connect ( currentWindow , iFrame ) . makeBridge ( 'Logout' ) . makeBridge ( 'ChangeLanguage' ) . addListener ( 'Logout' , ( message ) => console . debug ( `[Parent][Logout listener] The child has sent an empty message <Logout> to the parent` ) ) ; setTimeout ( ( ) => { bridge . sendMessage ( 'ChangeLanguage' , 'ru' ) ; setTimeout ( ( ) => { window . frames [ 0 ] . postMessage ( [ { channel : 'ChangeLanguage' , message : 'de' } ] , '*' ) ; } , 1000 ) ; } , 2000 ) ; } }