样式未从后端解析

Dee*_*ple 5 css text-styling angular

我有一个带有角度前端和 C# 后端的应用程序。我从我的应用程序的后端收到这个富文本:

<b>Hello <span style="font-weight:normal"> world </span></b>
Run Code Online (Sandbox Code Playgroud)

显示的是“ Hello world
我要显示的是“ Hello world”

所需的行为是跨度的样式不会被覆盖。此 codepen 示例显示了所需的行为,但仅限前端:https ://codepen.io/david-lo/pen/rNVOEbY

我错过了什么?

Dee*_*ple 2

我通过使用SafeHtmlDomSanitizer解决了我的问题:

前:

  public txt: string; //txt is rendered in my html file. 
  @Input() public set header(_txt: string) {
    this.txt = _txt;
  }
Run Code Online (Sandbox Code Playgroud)

输入的字符串_txt有值<b>Hello <span style="font-weight:normal"> world </span></b>

问题是我的跨度样式被忽略,所以输出将是:

你好世界

后:

  public txt: SafeHtml;
  @Input() public set header(_txt: string) {
    this.txt= this.domSanitizer.bypassSecurityTrustHtml(_txt);
  }
Run Code Online (Sandbox Code Playgroud)

通过按照上面所示的方式使用 DomSanitizer,我的跨度样式在前端得到了尊重,并且我实现了所需的输出:

你好世界