skip to Main Content

I am beginner Angular developer.

i have this code:

export class KoniecComponent implements OnInit {

  ....
  wiadomosc: string;
  urlView: string;

  constructor(
    private cService: CService
  ) { }

  ngOnInit(): void {
    this.registerC();
  }

  registerC(): void {
    this.cService.saveC(this.szkoda).subscribe(
      wynik => {
       
        const json = JSON.stringify(wynik);
        let txt = JSON.parse(json);

        if(txt.result_info != "" && txt.result_info != null)
        {
          let msg = txt.result_info;
          let url = txt.pm;
          this.urlView = txt.pm;
          this.wiadomosc = msg.replace(txt.number, '<b>'+txt.number+'</b>');
        }
        else {
          ...............
        }
      },
      error => {
        .......
      }
    );
  }

}

I have problem with this line:

this.wiadomosc = msg.replace(txt.number, ‘‘+txt.number+’‘);

In result i have ‘b’ tabs – not bolded text.

How can i repeir it? Please help me

2

Answers


  1. Here you can use like this.
    this.wiadomosc = msg.replace(txt.number, '<b>{{txt.number}}</b>');

    Login or Signup to reply.
  2. If you want to load rich html text in angular then interpolation will not work
    you need to set it inside innerHTML attribute like this.
    <span [innerHTML]="wiadomosc"></span> this will load <b>test</b> test as bold in DOM

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search