-1

I got json Data that output text with returns: enter image description here

Now i try to output it with:

<div [innerHTML]="message.content"></div>

But the result is this: enter image description here

What can i do, that he show the returns?

Budi
  • 678
  • 2
  • 6
  • 27
  • returns are ignored by the browser, not by Angular. You either need to wrap in `
    ...
    ` or similar, or replace returns with `
    `. See also https://stackoverflow.com/questions/37076867/in-rc-1-some-styles-cant-be-added-using-binding-syntax/37076868#37076868
    – Günter Zöchbauer Aug 18 '17 at 09:55
  • 1
    why don't you use InnerText? .. does you need html?? – federico scamuzzi Aug 18 '17 at 09:55
  • Don't program this way. `[innerHTML]` is not designed as a way to construct arbitrary HTML. It's designed for very narrow, specific use cases, where you have data that happens to be pre-formatted in HTML. In any case, newlines are always ignored in HTML. If you want it to work some other way, try CSS properties such as `white-space`. –  Aug 18 '17 at 10:11
  • Thanks alot @federico scamuzzi! I didnt know that this directive exist! This works very well, thanks again! – Budi Aug 18 '17 at 10:25
  • happy to helped you!!! – federico scamuzzi Aug 18 '17 at 10:25

1 Answers1

0

The [innerHTML] will render HTML, when you are saying returns i'm assuming you are referring to \r\n carriage returns and line feeds. This is not HTML.

What you need to do is pass in HTML for your \r\n as for example <br />

Jamie Rees
  • 7,973
  • 2
  • 45
  • 83