Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript - How to append line break (\n) on string?

I'm trying to concatenate a string with a "\n" like this:

- Item 1
- Item 2
var msg: string = '';
msg += '- Campo NOME é obrigatório';
msg += "\n- Campo EMAIL é obrigatório";

But the output comes without the line break:

- Item 1 - Item 2

I searched a lot about it but I didn't find a solution. Could you please help me? :)

like image 837
Ana Paula Avatar asked Oct 23 '25 14:10

Ana Paula


1 Answers

If you rendering to HTML, you will want to use the HTML tag for a newline :

The string Hello\n\nTest in your source will look like this:

Hello!

Test

The string Hello<br><br>Test will look like this in HTML source:

Hello<br><br>Test

Try this :

var msg: string = "";
msg += "- Campo NOME é obrigatório";
msg += "<br/>- Campo EMAIL é obrigatório";

Here is fiddle : https://jsfiddle.net/9fuxgbms/1/

like image 192
Jagjeet Singh Avatar answered Oct 26 '25 05:10

Jagjeet Singh