Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript/angular: add 'line break' via string

I have this method in my .ts file that creates a string out of obj.date and obj.status.
Now I'm using multiple(eight, to be exact) \xa0 (a hex encoded nbsp) to make some space between the date and the status.
The resulting string: 17/11/2020       done
is then bound in the template.

I would rather use a line break instead so that it would look like so:
17/11/2020
done

dateWithStatus(obj) {
  return
    moment.utc(object.date).format(DATE_FORMAT)
    + Array(8).fill('\xa0').join('')
    + object.status;
}

My question is - what hex code should I use instead of \xa0 to force the line break?
Neither \n, nor \r\n seem to work.

PS: Yes, I did search the stackoverflow (among other sites) for the answer, to no avail.


=== update === I tested the string literal thingy in the (Angular) template file.


component.ts
testString = `abcd
efgh
ijkl`;

component.html
<span>{{testString}}</span>

RESULT : all the letters are in one line
abcd efgh ijkl

like image 584
PaxForce Avatar asked Apr 06 '26 01:04

PaxForce


1 Answers

One of the ways could be adding a class to your element, say, testString, like so:-

.testString{
white-space:pre
}

white-space:pre should allow breaking at \n characters.

like image 166
Lakshya Thakur Avatar answered Apr 08 '26 13:04

Lakshya Thakur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!