iframe未在angular4应用程序中加载src
在我的应用程序中,我正在将youtube视频加载到iframe中。 我已经清理了url。但是当我运行应用程序时,src属性没有加载 以下是html:iframe未在angular4应用程序中加载src,angular,iframe,src,Angular,Iframe,Src,在我的应用程序中,我正在将youtube视频加载到iframe中。 我已经清理了url。但是当我运行应用程序时,src属性没有加载 以下是html: <a [href]="data.url" target="_blank" *ngIf="data.contentTypeString=='YOUTUBE_VIDEO' && data.url != null"> <div class="embed-responsive embed-respo
<a [href]="data.url" target="_blank" *ngIf="data.contentTypeString=='YOUTUBE_VIDEO' && data.url != null">
<div class="embed-responsive embed-responsive-16by9">
<iframe *ngIf="data.contentTypeString=='YOUTUBE_VIDEO'"
class="embed-responsive-item"
src="{{data.url}}"></iframe>
</div>
</a>
当我查看youtubeURL的日志时,它是这样的:
youtubeUrl=====SafeValue必须使用[property]=绑定:
(见附件)
错误:需要一个安全的资源URL,获取了一个URL(请参阅
)
在DomSanitizerImpl.checkNotSafeValue处(
请导游。
谢谢。你需要做这样的事情 TS
import { DomSanitizer } from '@angular/platform-browser';
this.current_url=this.sanitizer.bypassSecurityTrustResourceUrl(url)
模板
<iframe id="frame" frameborder="0" [src]="current_url"></iframe>
评论后更新
只需做一些类似于
[src]=“current_url”
或[attr.src]=“
的事情,它认为这是由于domsanization
issue@ShrutiSee你的控制台,有错误吗?请看下面的答案:[src]=“data.url”
我已经用sanitiz方法更新了我的问题,然后你只需要做一些类似[src]的事情=“url”
。你应该用整个方法更新问题,因为这是第一个失败点。注意:我已经做了你所说的一切,但仍然不起作用。尝试使用嵌入url,而不是常规的https://www.youtube.com/embed/video-ID
@ShrutiNairI也有同样的问题。
<iframe id="frame" frameborder="0" [src]="current_url"></iframe>