gpt4 book ai didi

javascript - 更改特定单词的颜色

转载 作者:行者123 更新时间:2023-12-03 04:34:58 25 4
gpt4 key购买 nike

我有一个从 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 no valor de R$:5762 <span style="color: red">recusada</span>

最佳答案

您必须使用 innerHTML 才能呈现 html

所以你的代码应该是这样的

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

plunkr

关于javascript - 更改特定单词的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43333560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com