我试图在*ngfor中调用一个函数,但它重复了数据绑定。如何在ngfor循环中调用函数?
我的视图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>
我的product.component.ts文件
GetProductQuanityByCustomer(productId:number)
{
this._productservice.GetProductQuantityByCustomer( productId,122 ).subscribe( p=>this.productQuantity=p )
return this.productQuantity;
}
发布于 2016-09-09 19:51:27
我将从代码中调用它,并将其赋给组件中的一个变量。
productQuantity: number = 0;
.
.
.
productQuantity = GetProductQuanityByCustomer(number)
但根据https://angular.io/docs/ts/latest/guide/template-syntax.html的说法。您可以使用表达式:
{{GetProductQuanityByCustomer(product.id)}}
https://stackoverflow.com/questions/39410637
复制相似问题