Angular 5无法显示iFrame
创始人
2024-10-15 23:00:46
0

问题描述: 在Angular 5应用程序中,尝试显示iFrame时,iFrame内容无法正确显示。

解决方法:

  1. 在组件的HTML文件中添加一个iFrame元素,并为其指定一个唯一的id:

  1. 在组件的TypeScript文件中,使用@ViewChild装饰器获取对iFrame元素的引用:
import { Component, ViewChild, ElementRef } from '@angular/core';

@Component({
  selector: 'app-my-component',
  templateUrl: './my-component.component.html',
  styleUrls: ['./my-component.component.css']
})
export class MyComponent {
  @ViewChild('myIframe') myIframe: ElementRef;
}
  1. 在组件类的ngAfterViewInit生命周期钩子函数中,配置iFrame的src属性:
import { Component, ViewChild, ElementRef, AfterViewInit } from '@angular/core';

@Component({
  selector: 'app-my-component',
  templateUrl: './my-component.component.html',
  styleUrls: ['./my-component.component.css']
})
export class MyComponent implements AfterViewInit {
  @ViewChild('myIframe') myIframe: ElementRef;

  ngAfterViewInit() {
    const iframe = this.myIframe.nativeElement;
    iframe.src = 'https://example.com'; // 替换为你想要显示的iFrame的URL
  }
}
  1. 确保在Angular应用程序的模板中使用组件:

这样,当组件加载完成后,iFrame将显示指定的URL的内容。

相关内容

热门资讯

透视开挂!hhpoker德州挂... 透视开挂!hhpoker德州挂真的有吗(透视)约局吧开挂神器是真的吗,教程模板(有挂工具)-哔哩哔哩...
epoker免费透视脚本!德州... epoker免费透视脚本!德州透视是真的假的(透视)app-都是揭露真的有挂1)德州透视是真的假的辅...
透视科普!fishpoker透... 透视科普!fishpoker透视底牌(透视)wepoker私人辅助器,教程指南书(证实有挂)-哔哩哔...
aapoker万能辅助器!wp... aapoker万能辅助器!wpk辅助哪里买(透视)技巧-本来揭露有挂该软件可以轻松地帮助玩家将aap...
透视了解!hhpoker辅助软... 透视了解!hhpoker辅助软件下载(透视)wepoker有插件吗,教程大纲(真是有挂)-哔哩哔哩1...
wejoker辅助器要钱玩吗!... wejoker辅助器要钱玩吗!线上德州的辅助器是什么(透视)软件-果然解迷有挂线上德州的辅助器是什么...
透视关于!wepoker透视有... 透视关于!wepoker透视有用吗(透视)wpk可以透视吗,教程窍门(有挂教学)-哔哩哔哩1、完成w...
aapoker真的假的!wep... aapoker真的假的!wepoker透视脚本下载(透视)挂-竟然详细存在有挂wepoker透视脚本...
透视关于!xpoker透视辅助... 透视关于!xpoker透视辅助(透视)约局吧德州透视,教程教程书(有挂规律)-哔哩哔哩约局吧德州透视...
hhpoker软件靠谱吗!we... hhpoker软件靠谱吗!wepoker私人局开挂视频(透视)教程-一直推荐是真的挂亲,关键说明,w...