如何在角度值绑定中执行嵌入的html标记,如:{{variable}}?

如何在角度值绑定中执行嵌入的html标记,如:{{variable}}?,html,angular,string,dynamic,interpolation,Html,Angular,String,Dynamic,Interpolation,我有一个变量,其中字符串由用户传递 let string = "we found {value} locations in {city} city. please search another city." 我想向用户显示它,我需要用一些值替换它。我正在展示这样的信息: <p>{{string}}</p> this.string = this.string.replace("{value}", this.count) this.

我有一个变量,其中字符串由用户传递

let string = "we found {value} locations in {city} city. please search another city."
我想向用户显示它,我需要用一些值替换它。我正在展示这样的信息:

<p>{{string}}</p>
this.string = this.string.replace("{value}", this.count)
this.string = this.string.replace("{city}", this.city)
this.string = this.string.replace("{value}", '<b>' + this.count + '</b>')
this.string = this.string.replace("{city}", '<b>' + this.city + '</b>')
然后将此字符串显示为html。。那很好。但我想用粗体替换html中的值

我尝试过这样附加:

<p>{{string}}</p>
this.string = this.string.replace("{value}", this.count)
this.string = this.string.replace("{city}", this.city)
this.string = this.string.replace("{value}", '<b>' + this.count + '</b>')
this.string = this.string.replace("{city}", '<b>' + this.city + '</b>')
this.string=this.string.replace(“{value}”,“”+this.count+“”)
this.string=this.string.replace(“{city}”,“”+this.city+“”)
但这也会在UI中打印
。 我不知道如何插入这个字符串

我不想使用InnerHTML方法使用VanillaJS将字符串替换为选择器

如果有人对带有样式的动态字符串中的
插值有深入的了解
,请帮助我


注意:简而言之,{{variable}}应该以角度执行
“HTML”

像这样使用innerHTML:

<p [innerHTML]="string"></p>


我为执行html创建了这个。但还有其他方法可以做到这一点。那么请在这里回答。会的appreciated@yazan,这是另一种解决方案,它实际上改变了该标记中的整个内部html。我需要在angular中进行高级插值,以便能够在该组件的html模板中仅修改该字符串。您可以为该案例创建自定义管道。管道将修改您的字符串,替换任何字符串并设置您提供的文本的样式,用法如下所示

并修改编辑管道中的字符串,请参见感谢好友的回答,但是,我已经尝试过了,并且成功地工作了。。。我需要另一种方式来用angularWelcome中的Advanced interpolation来显示它,虽然我不确定你所说的“Advanced interpolation”是什么意思,但如果你再解释一下你的需要,我也许可以帮你。简单的interpolation是这样的:“这是
${variable}
value”,我不能在这个变量中编写任何html,因为它在UI中打印。我需要将存储在变量中的html执行到这个html中。简而言之,我想:“这是
${10}
value”10在html中应该是粗体的