Angular ignores line break in String


I'm putting together a message with several messages in JAVA. After mounted send to the front / view however the angular is eating all breaks of lines:

public String salvarPorXLS(){

while (rowIterator.hasNext()) {
    pErrors += "\n"+"Atividade do processo: " + numeroProcesso + " cadastrada com sucesso"+"\n";

return pErrors;



Process activity: 00003362920178178224, successfully registered   Activity of the case: 00003362920178178224   Activity of the case: 00032906420158172001   Activity of the case: 00032906420158172001   Activity of the process: 00032906420158172001

You're not breaking the line after the word success!

The angular is disturbing the exit:

asked by anonymous 18.09.2018 / 15:25

1 answer


If the output is in html, then \n is not a line break - in html, a \n character is a whitespace such as space ( \x20 ) and tab (% \t ).

If your output is in HTML, you should be putting each message into an appropriate semantic element - using the rules of your framework for this. If your string is going to be used as direct HTML, instead of being processed by the Framework in a template, you could for example put the errors inside <li>...</li> elements, and all within <ul>...</ul> .

Or, the "fast and cheap" way, use a <br> where you're putting \n . Another way is to keep the output as it is, and change the page layout style (CSS) - use CSS so that the HTML element that will display the block of your error messages treats \n as a line break - this can be done by placing the white-space: pre-line; property in the appropriate element, for example. (tip of @fernandosavio)

By the way, \n is not anything "magic" - it's just the linefeed character, with decimal code 16 (0x10) - and escape \n to represent it is inherited from C language - among other things , the only thing you get by writing something like "\n" + "minha frase" instead of simply "\nminha frase" is to type a lot of more things - there's no need for it.

18.09.2018 / 15:41