Home > Net >  Empty spaces added around HTML text when using Angular interpolation
Empty spaces added around HTML text when using Angular interpolation

Time:04-16

Any idea why an empty space is added before text in HTML when using interpolation in Angular?

Exemple in my Angular HTML template:

<div >
     {{ "Beds" }}
</div>

Result after ng serve:

<div _ngcontent-bej-c49="" > Beds </div>

You can see that some spaces are added before and after Beds.

Do you have any idea of what I could do to prevent those spaces from appearing?

This is an exemple and I'm aware that there's no need to use an interpolation here.

CodePudding user response:

Remove the whitespace before and after the JavaScript.

<div >{{ property.bedAmount > 1 ? "Beds" : "Bed" }}</div>
  • Related