skip to Main Content

How can I replace my binding data’s < br > with line break?
like: passing data:
Hello< br >welcome to this group< br >type your text

and viewing data will be :
Hello
welcome to this group
type your text

to replace < br > with line break, I have used [innerHTML] like, <p [innerHTML]="a.Details">

; but here problem is, all letter are come as Capital formate.
Is there any alter form?

3

Answers


  1. You can use different div.

    eg.

    <div> Hello </div>
    <div> welcome to this group </div>
    <div> type your text </div>
    
    Login or Signup to reply.
  2. You can use this way to update your code :

    <p [innerHTML]="replaceBreaksWithLineBreaks(a.Details.toLowerCase())"></p>
    

    and your JS function

     replaceBreaksWithLineBreaks(text: string): string {
      return text.replace(/<br>/g, 'n');
    }
    
    Login or Signup to reply.
  3. You could split the text from <br> and will have an array of each line.
    on the HTML side you can loop through the lines and use <p *ngFor=let line of text>{{line}}</P> to display them.

    .ts file

      text: string = 'Hello< br >welcome to this group< br >type your text';
    
      lines: string[] = this.text.split('< br >');
    

    .html file

    <p *ngFor="let line of lines">{{line}}</p>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search