Im trying to output the address details of the user from backend and to display on html page in an ionic angular project
Here the address details has three fields
Address line1 (mandatory), Address line2 and Address line 3 (non mandatory)
when i try to out these address details in line separated by commas. iam getting extra commas when addressline 2 and 3 are not filled.
i want the commas to shown only if the next two fields are filled else dont want to show
Below is my code.
TS File:
getAddress() {
this.apiService.getAddress().then(
res => {
this.primaryAddrArray = [this.primaryAddress.addressLine1, this.primaryAddress.addressLine2, this.primaryAddress.addressLine3];
}
}
HTML page:
<h1> Address: </h1>
<p *ngFor="let addr of primaryAddrArray; let i=index">{{addr}}, </p>
because of the comma used after {{addr}} iam getting after each address line.
also tried like this
<h1> Address: </h1>
<p *ngFor="let addr of primaryAddrArray; let i=index">{{addr} {{primaryAddrArray = null ? ' ' : ','}} </p>
getting output as
Address:
9th Avenue block,,,
I dont want extra commas if the remaining two address fields are not filled. please assist me on this. thank you.