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

相关内容

热门资讯

透视揭露!来玩app破解(透视... 透视揭露!来玩app破解(透视)红龙poker有辅助吗,教程烘培(真是有挂)-哔哩哔哩1、很好的工具...
wepoker怎么破解游戏!w... 您好,wepoker辅助是真的假的这款游戏可以开挂的,确实是有挂的,需要了解加去威信【4852750...
透视有挂!德州私人局脚本(透视... 透视有挂!德州私人局脚本(透视)we-poker是什么软件,教程策略(有挂分析)-哔哩哔哩1、透视有...
wepoker底牌透视!wep... wepoker底牌透视!wepoker好友房开挂(透视)方法-原来透视是真的挂1、游戏颠覆性的策略玩...
透视曝光!wepoker-h5... 透视曝光!wepoker-h5下载(透视)wepoker脚本下载,教程方针(有挂方法)-哔哩哔哩1、...
wepoker私人局可以透视!... 您好,wepoker私人局可以透视这款游戏可以开挂的,确实是有挂的,需要了解加去威信【4852750...
透视解密!aa poker辅助... 透视解密!aa poker辅助(透视)sohoo辅助,教程诀窍(竟然有挂)-哔哩哔哩1、aa pok...
hhpoker可以控制吗!we... hhpoker可以控制吗!wepoker辅助器安装包(透视)插件-竟然解迷是有挂1、下载好wepok...
透视有挂!hhpoker辅助软... 透视有挂!hhpoker辅助软件(透视)拱趴大菠萝挂,教程练习(了解有挂)-哔哩哔哩1、金币登录送、...
大菠萝辅助器!aapoker能... 大菠萝辅助器!aapoker能控制牌吗(透视)教程-果然必备是真的挂1、打开软件启动之后找到中间准星...