[英]how to use routerLink instead of href in anchor tag in 'innerHTML' in angular2+?
[英]how to use innerHTML when the string is an Iframe tag in angular
有一個字符串類型變量,其中包含一個 iframe 標記。 我需要 angular 將字符串識別為 iframe HTML 標記並填充 HTML。
目前,angular 正在構建它的字符串。
請檢查以下代碼
變量:
this.longDesc = "<iframe width="something" height="something" src="something" ></iframe>"
html文件
<div class="description-panel" [innerHTML]="longDesc" ></div>
步驟1:在ts文件中導入以下部分
import {DomSanitizer} from '@angular/platform-browser';
第 2 步:在特定的 ts 文件中定義構造函數
constructor(private domSanitizer:DomSanitizer) {}
第 3 步:-根據要求(方法/函數或構造函數)在 ts 文件中使用以下代碼
this._EmittersService.longDescemitted$.subscribe(obj => {
this.longDesc = this.domSanitizer.bypassSecurityTrustHtml(obj or any html content);
or
this.longDesc = this.domSanitizer.bypassSecurityTrustHtml('<iframe width="something" height="something" src="something" ></iframe>')
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.