iframe - 角度 6 组件功能不适用于 iframe 的 HostListener
问题描述
我在 iframe 中有一个 Angular 6 应用程序和一个不同的 Web 应用程序。当我使用 postmessage 函数从 iframe 接收消息时,我确实进入了 onMessage 函数,然后我确实进入了 openOffNet - 但随后弹出窗口不起作用。当我从按钮激活弹出窗口时它不起作用。有人知道为什么它不起作用吗?
谢谢你
import {HostListener, Component, OnInit } from '@angular/core';
import {NgbModal, NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
import {NgbdModalContentComponent} from '../ngbd-modal-content/ngbd-modal-content.component';
import {ModalAddDeviceComponent} from '../popupBoxes/modal-add-device/modal-add-device.component';
import {ModalAddOffnetComponent} from '../popupBoxes/modal-add-offnet/modal-add-offnet.component';
@Component({
selector: 'app-top-bar',
templateUrl: './top-bar.component.html',
styleUrls: ['./top-bar.component.css']
})
export class TopBarComponent implements OnInit {
constructor(private modalService: NgbModal) {
(<any>window).onMessage= this.onMessage.bind(this);
}
ngOnInit() {
}
@HostListener('window:message', ['$event'])
onMessage(e) {
console.log('HostListener');
if(e.data.function == 'subnetworkClicked'){
}
else{
console.log("open popUp");
this.openOffNet();
}
}
openOffNet () : void {
const modalRef = this.modalService.open(ModalAddOffnetComponent);
}
}
解决方案
尝试 'document:message' 而不是 'window:message'
推荐阅读
- amazon-web-services - 如何以编程方式下载 Sagemaker 笔记本实例中的文件?
- c++ - 使用线程时如何避免全局信号量和队列
- android - 当另一个应用程序激活时如何启动服务?
- docker - 如何在詹金斯作业中从容器内的脚本运行 repo
- python - 为什么 Python pyusb usb.core 访问由于权限而被拒绝,为什么 rules.d 不能修复它?
- logstash - Logstash:最简单的管道可能无法正常工作
- javascript - 使用猫鼬的嵌套查询
- php - Composer - Windows 安装程序被卡住
- alibaba-cloud-ecs - 如何在 E-MapReduce 控制台上创建网关
- c++ - C++:如何为用户类型重载 pow?