Reputation: 49
I tried to call a function inside the *ngfor but it repeats data binding. How can I call a function inside ngfor loop
My View product.html
<ion-item ion-item *ngFor="let product of productlist">
<ion-thumbnail item-left>
<img src={{product.picturePath}}>
</ion-thumbnail>
<ion-grid>
<ion-row>
<ion-col width-60>
<h2>{{product.name}}</h2>
<p>500 GM</p>
<p>$100</p>
</ion-col>
<ion-col width-40>
<ion-icon name="remove-circle"></ion-icon>
</button> -->
<span item-right >GetProductQuanityByCustomer(product.id)</span>
</ion-col>
</ion-row>
</ion-grid>
</ion-item>
</ion-list>
</ion-content>
My product.component.ts file
GetProductQuanityByCustomer(productId:number)
{
this._productservice.GetProductQuantityByCustomer( productId,122 ).subscribe( p=>this.productQuantity=p )
return this.productQuantity;
}
Upvotes: 0
Views: 7762
Reputation: 1120
I woul invoke it from code and assign to an variable in component.
productQuantity: number = 0;
.
.
.
productQuantity = GetProductQuanityByCustomer(number)
But according to https://angular.io/docs/ts/latest/guide/template-syntax.html. You can use expression:
{{GetProductQuanityByCustomer(product.id)}}
Upvotes: 1