1
我有一個返回HTML代碼的API(其中包含iframe對象)。角度清潔劑 - YouTube iframe的例外
發送到客戶端的代碼如下所示:
<p>Something blabla</p>
<iframe allowfullscreen="true" frameborder="0" height="270" src="https://www.youtube.com/embed/someID?feature=oembed" width="480"></iframe>
現在,我怎麼能在YouTube添加一個例外,僅清潔劑?問題是,HTML代碼是用戶輸入(並非完全用戶輸入,但僅限於我信任的人,因此我猜這沒有安全風險),所以我不能使用bypassSecurityTrustResourceUrl,對吧?
我的代碼(page.component.ts)
constructor(private _router: Router, private _http: Http, private _sanitizer: DomSanitizer) {
this.fetchNews();
}
fetchNews() {
this._http
.get(this.urlAPI)
.map((response: Response) => {
let json = response.json();
this.content = json.results[0].content;
}).subscribe();
}
和HTML(page.component.html):
<div [innerHTML]="content">
</div>
沒有你發現同樣的任何解決方案,因爲我也面臨同樣的問題 –
不幸的是沒有,但如果我這樣做,我會在這裏發佈的解決方案。 – GTX