2017-04-10 103 views
0

我有一个我从json获取的文本,并且我想要更改文字上出现的某些单词的颜色,例如recusada。我创建了一个管道,试图做到这一点:更改特定单词的颜色

transform(valor:any):any{ 
    console.log("texto", valor); 
    return valor.replace(/recusada/, '<span style="color: red">$&</span>'); 
} 

这是HTML:

<p *ngFor="let historico of disputa.historico"> {{historico.texto | filtroHistorico: historico.texto}} </p> 

唯一的问题是,而不是仅仅改变recusada颜色为红色的文字是这样的:

Proposta无勇气去R $:5762 <span style="color: red">recusada</span>

回答

1

您必须使用innerHTML才能呈现html

所以,你的代码看起来应该是这样

<p *ngFor="let historico of disputa.historico" [innerHTML]="historico.texto | filtroHistorico: historico.texto"> </p> 

plunkr

+0

哇,没现在有像'innerHtml'这样的属性,非常感谢你的人:) –