In an Angular 10 app I have a string that's composed of several template literals passed in from a function:
getFormattedAddress(addr): string {
const nameAndAddress = `
${addr.name}
${addr.address}
${addr.city}, ${addr.state} ${addr.postalCode}, ${addr.country}
`;
return nameAndAddress;
}
and used in the template as such:
{{ getFormattedAddress(senderAddress) }}
Everything I read about template string literals says if you split it onto lines like I have it will come back a multiline string. Does this not apply the way I am trying to use it here?
For now, I have used [innerHTML]
to do it, like so:
<div [innerHTML]="getFormattedAddress(shipment.senderAddress)"></div>
and modified my function to use <br>
tags:
getFormattedAddress(addr): string {
const nameAndAddress = `
${addr.name} <br>
${addr.address} <br>
${addr.city}, ${addr.state} ${addr.postalCode}, ${addr.country}
`;
return nameAndAddress;
}
Is this the only way? Can't I construct a multiline template literal and return it to a template binding?