🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

angular-post-me-service

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-post-me-service

Angular service using the post-me library for bidirectional communication between browser windows/frames via window.postMessage

0.10.2
latest
70

Supply Chain Security

100

Vulnerability

88

Quality

76

Maintenance

100

License

Version published
Weekly downloads
99
11.24%
Maintainers
1
Weekly downloads
 
Created

angular-post-me-service

Angular service using the post-me library for bidirectional communication between browser windows/frames via window.postMessage

Installation

npm install angular-post-me-service

Usage

Parent Window

import PostMeService from 'angular-post-me-service';
import { ElementRef, OnDestroy } from "@angular/core";

export class SomeComponent implements OnDestroy {
  @ViewChild('iframe') iframeRef: ElementRef;

  constructor(private postMeService: PostMeService) {
    this.postMeService.registerMethod('add', async (a: number, b: number) => {
      return a + b;
    });
    const {origin} = window.location;
    this.postMeService.connectToChildWindow(
      this.iframeRef.nativeElement.contentWindow,
      origin,
    ).then(connection => {
      connection?.request('subtract', 6, 2).then(result => {
        console.log(result);  // 4
      });
    });
  }

  ngOnDestroy() {
    this.postMeService.unregisterMethod('add');
  }
}

Child Window (e.g. iframe)

import PostMeService from 'angular-post-me-service';
import { ElementRef, OnDestroy } from "@angular/core";

export class SomeComponent implements OnDestroy {
  @ViewChild('iframe') iframeRef: ElementRef;

  constructor(private postMeService: PostMeService) {
    this.postMeService.registerMethod('subtract', async (a: number, b: number) => {
      return a - b;
    });
    const {origin} = window.location;
    this.postMeService.connectToParentWindow(parent, origin).then(connection => {
      connection?.request('add', 6, 2).then(result => {
        console.log(result);  // 8
      });
    });
  }

  ngOnDestroy() {
    this.postMeService.unregisterMethod('subtract');
  }
}

FAQs

Package last updated on 22 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts