我想知道是否有一种简单的方法将字符串转换为HTML,就像我尝试将具有有效html的字符串转换为HTML,href链接和换行符一样。我使用DOMParser().parseFromString
https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
方法
new DOMParser().parseFromString(
"....snip..... <br><br> If you do not have an account, please register here.<a href= https://redmine.ixsystems.com/account/register </a>", 'text/html'
)
答案 0 :(得分:0)
你在Angular,以Angular方式做到:
constructor(private sanitizer: DomSanitizer) {
this.sanitizer.bypassSecurityTrustHtml('<p>Your HTML</p>');
}