2017-03-13 35 views
0

我從發球HTML標籤,就像這樣:ionic2:在<ion-content></離子含量顯示html標籤

<fieldset><legend><b>Basic Info</b></legend><ul><li><label>ProjectName :</label><span>test project name</span></li><li><label>ProjectCode :</label><span>SZ201611</span></li><li><label>ProjectType :</label><span>SZ</span</fieldset><fieldset> 

我準備在<ion-content></ion-content>顯示此像這樣:

<ion-content class="detail-style"> 
    <div [innerHTML]="html"> 
    </div> 
</ion-content> 

但問題是<fieldset><legend>標籤已經不存在了。那就是當我用chrome瀏覽器查看源代碼時,我發現fieldset和legend標籤消失了。就像被innerTHML標籤過濾一樣。

回答

0

也許您應該使用ng-bind-html將html綁定到DOM。

<div ng-bind-html="expression"> </div>

ng-bind-html

+0

離子2使用角2 ..這看起來像angularjs 1 –

0

我解決這個問題。

import {DomSanitizer} from '@angular/platform-browser'; 

constructor(private sanitize: DomSanitizer){ 
} 
...... 
this.html = this.sanitize.bypassSecurityTrustHtml(html); 
...... 

在HTML

<ion-content class="detail-style"> 
    <div [innerHTML]="html"> 
    </div> 
</ion-content>