I have two string. and I want to display the second string from new line. But I have to use only one variable in html.
let msg = "hello"+\n+"how r u";
I have to concat two string but start the second string from new line.
To start a new line of text or add spacing between lines or paragraphs of text in a worksheet cell, press Alt+Enter to insert a line break. Double-click the cell in which you want to insert a line break (or select the cell and then press F2).
On all versions of Microsoft Excel for the PC and Windows, the keyboard shortcut Alt + Enter moves to the next line. To use this keyboard shortcut, type text in the cell and when ready for a new line, press and hold down the Alt key, then press the Enter key. The shortcut key can be used as many times as needed.
To do a line break in HTML, use the <br> tag. Simply place the tag wherever you want to force a line break. Since an HTML line break is an empty element, there's no closing tag.
<br>: The Line Break element. The <br> HTML element produces a line break in text (carriage-return). It is useful for writing a poem or an address, where the division of lines is significant.
Import DomSanitizationService
.
import {DomSanitizationService} from '@angular/platform-browser';
in constructor of class do this
constructor(sanitizer: DomSanitizationService) {
this.msg = "Hello" + "<br/>" + "How are you?";
this.msg = this.sanitizer.bypassSecurityTrustHtml(this.msg);
}
Use msg
in the template as shown below
<p [innerHTML]="msg"></p>
Since you have not described your problem completely, one possible and simple way is to use split
function.
<p>{{msg.split('\n')[0]}}</p>
<p>{{msg.split('\n')[1]}}</p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With