我正在使用innerHtml并在我的cms中设置html,响应似乎没问题,如果我像这样打印: {{ poi.content }}
它给了我正确的内容: `
<table border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td style="vertical-align: top;">Tes11t</td>
<td style="width: 2px;"> </td>
<td style="width: 1px;"><img alt="midgetgolf-sport-faciliteiten-vakantiepark-2.jpg" src="http://beeksebergen.dev/app_dev.php/media/cache/resolve/full_size/midgetgolf-sport-faciliteiten-vakantiepark-2.jpg" style="height: 67px; width: 100px;" /></td>
</tr>
</tbody>
</table>
`
但是当我使用[innerHtml]="poi.content"
时,它会给我这个html:
<table border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td>Tes11t</td>
<td> </td>
<td><img alt="midgetgolf-sport-faciliteiten-vakantiepark-2.jpg" src="http://beeksebergen.dev/app_dev.php/media/cache/resolve/full_size/midgetgolf-sport-faciliteiten-vakantiepark-2.jpg"></td>
</tr>
</tbody>
</table>
当我使用[innerHtml]
答案 0 :(得分:17)
Angular2清理动态添加的HTML,样式......
@Pipe({name: 'safeHtml'})
export class Safe {
constructor(private sanitizer:DomSanitizer){}
transform(html) {
return this.sanitizer.bypassSecurityTrustHtml(html);
}
}
[innerHtml]="poi.content | safeHtml"
见