0

I have a list of items. I am trying to split them with a delimiter. It is working with semicolons, but not working with newline characters. How can I fix this, to work with new line? Would like to show line breaks.

This works:

[value]="productList.join('; ')"

Does not work for

[value]="productList.join('\n ')"
[value]="productList.join('\r ')"
[value]="productList.join('\n\r ')"

Currently using Angular 8 with Typescript.

Resource: JavaScript Newline Character

4
  • 4
    Define "doesn't work". If you want to show linebreaks in HTML you need to use <br /> tags. Consecutive whitespace is ignored; that's just how HTML and browsers work. Commented Jun 15, 2020 at 22:17
  • you have to replace \n for <br /> if you are using a textarea as an input and an HTML element as an output. This is not something related to angular is just how the web works. Commented Jun 15, 2020 at 22:22
  • It can; it's generally the wrong approach. If it works for your usecase, great. Commented Jun 15, 2020 at 22:26
  • @AlanSmith5482 Because that will preserve all whitespace, which may be acceptable in some situations, but it's almost always better to use the appropriate tags. Commented Jun 15, 2020 at 22:44

1 Answer 1

1

It should be working, create a css class with white-space

HTML:

[value]="productList.join('\n ')"

CSS:

.test{
  white-space: pre !important;
}
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.