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的内容。

相关内容

热门资讯

科技分享!大菠萝789辅助器下... 1、科技分享!大菠萝789辅助器下载,wepoker可以开透视吗,必胜教程(有挂技巧)。2、大菠萝7...
重要通知!newpoker怎么... 重要通知!newpoker怎么安装脚本,wpk透视是真的假的,扑克教程(有挂透视);《WPK辅助透视...
一分钟教你!wpk免费辅助,a... 一分钟教你!wpk免费辅助,aapoker辅助工具安全吗,微扑克教程(有挂攻略),支持语音通讯、好友...
玩家必备攻略!wepoker轻... 玩家必备攻略!wepoker轻量版书签,wepoker辅助器如何使用,专业教程(有挂教程)准备好在w...
盘点几款!wepoker私人局... 盘点几款!wepoker私人局俱乐部怎么进,佛手大菠萝辅助,爆料教程(有挂软件)1、玩家可以在wep...
一分钟了解!线上德州的辅助器是... 一分钟了解!线上德州的辅助器是什么,pokemomo辅助软件,AI教程(有挂攻略)1、不需要AI权限...
玩家交流!poker worl... 玩家交流!poker world辅助器,wepoker网页版透视方法,大神讲解(有挂软件)是一款可以...
程序员教你!wepoker底牌... 程序员教你!wepoker底牌透视,拱趴大菠萝开挂方法,玩家教你(有挂技巧)是一款可以让一直输的玩家...
实测揭晓!pokemmo手机版... 实测揭晓!pokemmo手机版脚本免费,wepoker私人局辅助,插件教程(有挂教程);原来确实真的...
最新通报!wpk插件,soho... 最新通报!wpk插件,sohoo辅助,揭秘教程(有挂攻略);1分钟了解详细教程(微信 1367043...