typescript - 更改角度材料中的选择时如何从后端获取url到iframe
问题描述
.html 页面
<iframe width="100%" height="100%" src="{{url}}" frameborder="0" allowfullscreen></iframe>
.ts 文件
this.url = 'https://www.youtube.com';
在基于 url ifrmae src 从下拉列表中更改选择时,应该更新。
解决方案
在 .html 页面中
<iframe width="100%" class="embed-responsive-item" height="100%" src="" frameborder="0" allowfullscreen></iframe>
在 .ts 文件中
import ElementRef from '@angular/core';
在构造函数中初始化它,如下所示
constructor(private hostElement: ElementRef)
在您想要触发的任何地方添加这些行。
const iframe = this.hostElement.nativeElement.querySelector('iframe');
iframe.src = 'https://www.youtube.com';
推荐阅读
- html - 下拉菜单栏问题
- git-bash - 无法在 Gitbash 中输入 backslah \
- python - 如何从字典或 json 文件中调用函数和变量
- image - 使用实体框架中的文件系统上传画廊图像
- spring-boot - 远程连接到自己的 Docker 网络中的 MariaDB Docker 容器
- c - mpi 矩阵乘法与不同数量的处理器一起运行
- kubernetes - 使用 Kubernetes 部署 YAML 文件将 Docker 映像部署到 Google Cloud 时未创建 pod
- angular - Angular Ivy i18n:找不到翻译
- javascript - 让表单在 if/else 语句中与 javascript 交互
- typescript - TypeScript 类构造函数中的可选参数