0

I have a string str = "hello"+ "\n"+ "my"+ "\n" + "World".

html binding <div>{{str}}</div>

I expected to print this string as

Hello
my
world

I'm failing to do it but in console I'm getting what I want. Did I missing any thing here..

DEMO

k11k2
  • 2,036
  • 2
  • 22
  • 36

1 Answers1

1

Add <br> instead of \n and use innnerHtml tag in html

this.str = 'Hello' +'<br>'+ 'my' +'<br>' + 'world';

<div [innerHTML]="str"></div>

Demo

Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80