首页 > 解决方案 > 更改角度材料中的选择时如何从后端获取url到iframe

问题描述

在此处输入图像描述

.html 页面

<iframe width="100%" height="100%" src="{{url}}" frameborder="0" allowfullscreen></iframe>

.ts 文件

 this.url = 'https://www.youtube.com';

在基于 url ifrmae src 从下拉列表中更改选择时,应该更新。

标签: typescriptangular-materialangular-material-8

解决方案


在 .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';

推荐阅读