0

I am trying to add a new line to a string in Angular application. In component.ts file I have added a variable which takes a string value.

heading="Lorem ipsum dolor sit amet. \n consetetur sadipscing elitr."

In component.html file I am calling this variable.

<div>{{heading}}</div>

But no new line is generated and the text is one single paragraph. Can someone help me with this.

2
  • In HTML a newline is achieved with a <br> Commented Jul 30, 2020 at 8:05
  • in HTML template use innerHTML binding... <h1 [innerHTML]="heading"></h1> and in component use... heading="Lorem ipsum dolor sit amet. <br> consetetur sadipscing elitr." Commented Jul 30, 2020 at 8:22

1 Answer 1

2

Try to add CSS style to to that Div.

div{
white-space:pre-line;
}

It should render \n in the browser.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.