Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make specific part of a string bold in Angular 2

I have an HTML code as below:

<div class="row">
      <div class="col-12" style="margin-top:15px;margin-bottom:10px">
            {{"description" | translate}}
      </div>
</div>

I am using ngTranslate to translate the description. The description is a key from my translation file, and the value of the key will be displayed.

The description will look like as below: "click cancel to cancel or click confirm to proceed".

I want to make the first cancel and confirm in the description to bold. How can I do that using css and angular 2?

like image 414
blackdaemon Avatar asked Sep 02 '17 04:09

blackdaemon


People also ask

How do you bold a part of a text in HTML?

HTML Formatting Elements<b> - Bold text. <strong> - Important text. <i> - Italic text.

How do you make a Div bold?

To make text bold in HTML, use the <b>… </b> tag or <strong>… </strong> tag. Both the tags have the same functioning, but <strong> tag adds semantic strong importance to the text.

What is the syntax of bold?

To bold text, add two asterisks or underscores before and after a word or phrase. To bold the middle of a word for emphasis, add two asterisks without spaces around the letters.


1 Answers

You should make use of [innerHTML], have html tags within your translations like this:

{
    "description": "click <strong>cancel</strong> to cancel or click <strong>confirm</strong> to proceed"
}

And in template bind it as html string:

<div [innerHTML]="'description' | translate"></div>

Please check the Official Documentation

Update: Working Plunker Example

like image 51
Shantanu Avatar answered Oct 17 '22 11:10

Shantanu