<h3>Center Align</h3>\n<p style=\"text-align: center;\">This is a paragraph. It is center aligned. Center is,but nature,a fence sitter. A flip flopper. It has a difficult time making up its mind. It wants to pick a side. Really,it does. It has the best intentions,but it tends to complicate matters more than help. The best you can do is try to win it over and hope for the best. I hear center align does take bribes.</p>
当我使用innerHTML时,渲染为:
<h3>Center Align</h3> <p> This is a paragraph. It is center aligned. Center is,but it tends to complicate matters more than help. The best you can do is try to win it over and hope for the best. I hear center align does take bribes. </p>
缺少< p>的转义属性标签所以我有一个空的< p>而不是< p style =“text-align:center;”>
constructor(private s: DomSanitizer) { this.text = 'my HTML'; this.text = s.bypassSecurityTrustHtml(this.text); }
见plunk.