如何使文本粗体在字符串字面角度?



嗨,我正在做Angular应用。我想让文本的某些部分加粗那么如何在字符串文本中做到这一点。

下面是.ts类中的代码:
if (res.status== "200") {
this.colortext = `${res.colorofthebus} color is the best of ${res.othercolor}`;
}

这里是。html:

{{colortext}}

如何使res.colorofthebus加粗,而其他字体为正常字体。

TIA。

使用innerHTML。参考文档

if (res.status== "200") {
this.colortext = `<b>${res.colorofthebus}</b> color is the best of ${res.othercolor}`;
}
...
<div [innerHTML]="colortext"></div>

html

<b>{{colortext?.colorofthebus}}</b> color is the best of {{colortext?.othercolor}}

.ts

。Colortext = res

一个可能的解决方案是使用angular的innerHtml,像这样:

.ts

this.colortext = `<strong>${res.colorofthebus}</strong> color is the best of ${res.othercolor}`;

. html

<span [innerHTML]="colortext"></span>

相关内容

最新更新