最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular - Make section of string variable bold - Stack Overflow

programmeradmin1浏览0评论

Is there any way in which I can make part of a string being assigned to a variable bold?

I have tried the following:

boldTxt = 'bold'

message = 'this text should be ' + this.boldTxt.toUpperCase().bold() ;

But what I get in the HTML is:

this should be <b>BOLD</b>

STACKBLITZ

Is there any way in which I can make part of a string being assigned to a variable bold?

I have tried the following:

boldTxt = 'bold'

message = 'this text should be ' + this.boldTxt.toUpperCase().bold() ;

But what I get in the HTML is:

this should be <b>BOLD</b>

STACKBLITZ

Share asked Aug 23, 2018 at 14:56 physicsboyphysicsboy 6,38822 gold badges77 silver badges139 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 6

You can use innerHTML, something like:

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

Setting the value of innerHTML removes all the element's contents and replaces them with nodes constructed by parsing the HTML set in the message variable. When the text is set using statement <p>{{message}}</p> the content is not parsed as HTML but as plain string.

发布评论

评论列表(0)

  1. 暂无评论