Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Angular使用带有转义元素属性的innerHTML大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨我从这样的休息服务器有一个html respose:

<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;”>

有没有办法使用其属性呈现此内容

解决方法

使用 DomSanitizer处理您的HTMl.认情况下这是不安全的.

constructor(private s: DomSanitizer) {
  this.text = 'my HTML';
  this.text = s.bypassSecurityTrustHtml(this.text);
}

plunk.

@H_489_33@

大佬总结

以上是大佬教程为你收集整理的Angular使用带有转义元素属性的innerHTML全部内容,希望文章能够帮你解决Angular使用带有转义元素属性的innerHTML所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。