apply bold text on part of string Angular

how to make a part of string bold in java
jquery bold text in string
how to make selected text bold in javascript
bold text in typescript
json bold text
javascript bold text in textarea
how to display bold text in javascript alert
angular strikethrough text

I would like to make a part of my text bold.

I get a text from a specific file.

"INFORMATION": "Here's an example of text",

I would want that Here's an to be bold.

"INFORMATION": "<b>Here's an</b> example of text",

"INFORMATION": "<strong>Here's an</strong> example of text"

Then I print it

<span translate>INFORMATION</span>

Instead of getting

Here's an example of text

I get

<b>Here's an</b> example of text


<strong>Here's an</strong> example of text


I'm trying innerHTML

<span [innerHTML]="information | translate"></span>

Information is variable containing text

but it's ignoring my html tags, it's printing only text

What I would do is a pipe that sanitizes the string you're giving to it, and use a regex to make it more generic. Something like this stackblitz :

import { Pipe, PipeTransform, Sanitizer, SecurityContext } from '@angular/core';

  name: 'boldSpan'
export class BoldSpanPipe implements PipeTransform {

    private sanitizer: Sanitizer
  ) {}

  transform(value: string, regex): any {
    return this.sanitize(this.replace(value, regex));

  replace(str, regex) {
    return str.replace(new RegExp(`(${regex})`, 'gi'), '<b>$1</b>');

  sanitize(str) {
    return this.sanitizer.sanitize(SecurityContext.HTML, str);

This way, the variable content doesn't actually change, meaning your data remains untouched.

How to make specific part of a string bold in Angular 2, 2 Answers. You have to split up the text to make specific part of the string bold in Angular 2 while you use translate. Back in 2015 I wrote a very popular tutorial called "Highlight Text in a String Using JavaScript and AngularJS," which is now worthy for an update. Things have changed between AngularJS and Angular, but the topic is still very valuable. Being able to manipulate HTML on the fly can solve many problems in Angular.

You can do this with angular-translate 2.0 if you have it.

<span translate="{{ 'INFORMATION' }}"></span> 

Highlight Text Within a String Using Angular and Regular , A sequence of characters that forms a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. “find and replace”-like� Using AngularJS and a few regular expressions (RegEx) with JavaScript, you can find text in a string and then apply your own customizations. The logic behind this example will be as follows: Use a regular expression to find a needle in a haystack; Replace the needles found with the same needle wrapped in a span tag

changing @user4676340's answer, to match string that is written like this: "blabla bold blabla" to return "blabla bold blabla" - Whatsapp style

import { Pipe, PipeTransform, Sanitizer, SecurityContext } from '@angular/core';
import { noop } from 'rxjs';

  name: 'boldText'
export class BoldTextPipe implements PipeTransform {

    private sanitizer: Sanitizer
  ) { }

  transform(value: string): any {
    const regex = /[\*][\w\W]*[\*]/gmi;
    return this.sanitize(this.replace(value, regex));

  replace(str, regex) {
    let matched = str.match(regex);
    matched ? matched.forEach(foundString => {
      foundString = foundString.substring(1, foundString.length - 1);
      str = str.replace(regex, `<b>${foundString}</b>`);
    }) : noop;
    return str;

  sanitize(str) {
    return this.sanitizer.sanitize(SecurityContext.HTML, str);

(using innerHTML in the component template)

TS: text="blabla bold blabla"

HTML: <p [innerHTML]="text | boldText"></p>

JavaScript String bold() Method, Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java� Which part would you like to make chages (bold text)? Text like it self (string value) cannot be bold or anything. But you can change its visibility when passign it to some control, like textbox: textBox1.Font = new Font(textBox1.Font, textBox1.Font.Style | FontStyle.Bold | FontStyle.Underline);

Bolding, Italicizing, and Underlining Portions of Text in NativeScript, NOTE: If you're using Angular with NativeScript the syntax you'll Notice how the code breaks the string into three parts, or spans. NativeScript has a special built-in directive to make use the same FormattedString class� apply bold text on part of string Angular. I would like to make a part of my text bold. I get a text from a specific file. "INFORMATION": "Here's an example of text

Working with Text Formatting in Angular DocumentEditor component , Document editor supports several formatting options for text like bold, italic, font This section describes how to modify the formatting for selected text in detail. public documentEditor: DocumentEditorComponent; public fontStyle: string[]� Cell Z1 = A1 and formatted the cell contents as bold Created a text box, clicked [F2] to link it to Cell B1, selected "No Line" for the text box formatting, and ensured the font was set to "regular". Position the text box. The only tricky part was making sure the text box fit in the row and the text was aligned with the text below.

Transforming Data Using Pipes, Use pipes to transform and format strings, currency amounts, dates, and other display data. UpperCasePipe : Transforms text to all upper case. the same pipe as part of an in-line template in a component that also sets the birthday value. The bold() method is not standard, and may not work as expected in all browsers. The bold() method is used to display a string in bold. This method returns the string embedded in the tag, like this: string

  • Where is the code where you try and display the text? It looks like you are just passing in a string not a html.
  • "INFORMATION": "<b>Here an</b> example of text",Here's my code containing the text. Then I print it inside <span>
  • is translate your own class or did you use a framework/library?
  • I use ngx-translate
  • It's only for Angular 1.x ?