2016-12-27 64 views
2

我有一個管道解碼html代碼。例如<p>test</p>成爲testPrimeng Datatable內的角度2管道給出安全錯誤

當我使用它的列裏面,它不顯示數據,但 'SafeValue must use [property]=binding: XXXX (see http://g.co/ng/security#xss)'

DATATABLE

<p-dataTable [value]="toShowSubVragen"> 

    <!-- WITH Pipe, DOESN'T WORK 
    SHOWS: SafeValue must use [property]=binding: XXXX (see http://g.co/ng/security#xss)--> 
    <p-column field="tekst" header="With Pipe"> 
     <template let-col let-vraag="rowData" pTemplate="body"> 
      <span>{{vraag[col.field] | safeHtml}}</span> 
     </template> 
    </p-column> 

    <!-- WITHOUT Pipe, WORKS 
    SHOWS: the tekst data.. --> 
    <p-column field="tekst" header="Without Pipe"> 
     <template let-col let-car="rowData" pTemplate="body"> 
      <span>{{car[col.field]}}</span> 
     </template> 
    </p-column> 

</p-dataTable> 

@Pipe({ name: 'safeHtml'}) 
export class SafeHtmlPipe implements PipeTransform { 
    constructor(private sanitized: DomSanitizer) {} 
    transform(value) { 
    return this.sanitized.bypassSecurityTrustHtml(value); 
    } 
} 

我該如何解決這個問題?

+0

@君特Zöchbauer'SafeValue'它不是來自我的數據。我想從管道的類 –

回答

2

使用safeHtml或直接與{{}}消毒劑是沒有意義的,因爲結果是字符串化,解除的| safeHtml應用。

<span>{{vraag[col.field] | safeHtml}}</span> 

也許你的意思是

<span [innerHTML]="vraag[col.field] | safeHtml"></span> 
+0

,這正是我錯了。謝謝!改行' {{vraag [col.field] | safeHtml}}'to'' –