小编vis*_*nuk的帖子

Angular 5 window.postmessage

我正在 Angular 6 中使用 Springboot API 后端开发一个应用程序。我目前正在开发一个加载 iframe 的应用程序。在子文档中,当我单击按钮时有一个提交按钮时,在来自该 API 的响应时在子文档中调用 API,我需要从该 API 获取响应。有没有人有什么建议?

下面是我在打字稿中的组件。如果需要,我可以包含其他代码,但我不知道是否需要。

Here is the Code.............

import { Component, OnInit, ViewChild, HostListener, ElementRef } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';

@Component({
  selector: 'app-auth-exception',
  templateUrl: './auth-exception.component.html',
  styleUrls: ['./auth-exception.component.css']
})
export class AuthExceptionComponent implements OnInit {


  constructor() {

    if (window.addEventListener) {
      window.addEventListener('message', this.receiveMessage.bind(this), false);
    } else {
      (<any>window).attachEvent('onmessage', this.receiveMessage.bind(this));
    }
  }

  ngOnInit() {
    window.addEventListener('message', () => {
      this.receiveMessage();
   }, false);
  }

  setEventListener() {
    const eventMethod = …
Run Code Online (Sandbox Code Playgroud)

iframe postmessage angular

5
推荐指数
1
解决办法
8654
查看次数

标签 统计

angular ×1

iframe ×1

postmessage ×1