0

I have a json file having multiline strings in a key.

"hello \r\n how are \r\n you"

I am trying to parse it using angular2 sanitizer

<p>Explanation : <span [innerHTML] = "explanationJSONString)"></span></p>

in the output, \r\n is omitted in HTML.

How can I have multiple line josn data in angualr2 template?

I also try just \ but it also doesnt work.

2
  • Have you tried just using \n Commented Mar 1, 2017 at 11:02
  • 3
    You should use <br> tag for newline if you are going to use it in html. Commented Mar 1, 2017 at 11:03

1 Answer 1

1

You can reuse pipes fot this.

Your markup

<span [innerHTML] = "explanationJSONString() | break"></span>

Your pipe

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'break'
})
export class BreakPipe implements PipeTransform {
  transform(value: string): any {
    return value.replace(/\r\n/g, '<br>');
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.