使用管道时AngularJS模板分析错误

使用管道时AngularJS模板分析错误,angular,typescript,angular-pipe,Angular,Typescript,Angular Pipe,我正在尝试清理来自我不控制的db的文本,并将其显示为html。我的坏代码如下所示 <li *ngFor="let comm of commList|async;"> <div class="notifBody"> <span> <div [innerHTML]={{comm.text|safe : 'html'}}> </div> </span> </div&g

我正在尝试清理来自我不控制的db的文本,并将其显示为html。我的坏代码如下所示

 <li *ngFor="let comm of commList|async;">
    <div class="notifBody">
      <span>
        <div [innerHTML]={{comm.text|safe : 'html'}}> </div>
      </span>
    </div>
 </li>
 import { Pipe, Sanitizer, SecurityContext } from '@angular/core';
 ...
 public transform(value: string, type: string): string {
    switch (type) {
        case 'html':
            return this.sanitizer.sanitize(SecurityContext.HTML, value);
    ...}}
谢谢

您可以使用:

[innerHTML]="comm.text|safe : 'html'"

但是您混合了两种语法[innerHTML]={{comm.text | safe:'html'}


您可以在此处阅读更多信息:

此处缺少a:*ngFor=let comm of commList | async;>?HTML属性值周围也缺少双引号。@OvidiuDolha已更新。在此处发布时意外删除了最后一个引号。JB:不知道你指的是什么。试试看,不带方括号。第一个建议行得通,但第二个建议不行。谢谢!有什么解释{{}有什么不同吗?@Davvit。缺少双引号,请尝试第二种方法。
<div class="notifBody">
  <span>
    {{comm.text|safe : 'html'}}
  </span>
</div>
 import { Pipe, Sanitizer, SecurityContext } from '@angular/core';
 ...
 public transform(value: string, type: string): string {
    switch (type) {
        case 'html':
            return this.sanitizer.sanitize(SecurityContext.HTML, value);
    ...}}
[innerHTML]="comm.text|safe : 'html'"
innerHTML="{{comm.text|safe : 'html'}}"