简体   繁体   English

Angular - [innerHTML] 在 Internet Explorer 上不起作用

[英]Angular - [innerHTML] doesn't work on Internet explorer

I have a seperate JSON file for translation, it looks like this:我有一个单独的 JSON 文件进行翻译,它看起来像这样:

  Title: "Welcome to <br> COVID-19 mitigation schemes",
  ...
} 

In angular when I write在 angular 我写的时候

<p [innerHTML]="Title"> {{Title}} </p>

It works fine on Chrome and Firefox, but on IE11, it still displays the <br> tag.它在 Chrome 和 Firefox 上运行良好,但在 IE11 上,它仍然显示<br>标签。

Any suggestions?有什么建议么?

PS - I need the JSON files for translations. PS - 我需要 JSON 文件进行翻译。 The reason I needed <br> was because the text was wrapping at the hyphen on COVID-19.我需要<br>的原因是因为文本在 COVID-19 的连字符处换行。 There may be other solutions, but I also need to add <a> tags in the middle of the given text.可能还有其他解决方案,但我还需要在给定文本的中间添加<a>标签。

I could use DomSanitization but ngx-translate does not work properly when I use it in TS file, even when I subscribe to the event.我可以使用 DomSanitization,但是当我在 TS 文件中使用它时,即使我订阅了事件,ngx-translate 也无法正常工作。 The code for that looks like this代码看起来像这样

this.translateService.get(`Title`).subscribe(data => this.title = data)

Any help would be great!任何帮助都会很棒!

use this one:使用这个:

 bypassSecurityTrustHtml(text: string) {
    return this.sanitized.bypassSecurityTrustHtml(text)

  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM