首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Angular2中调用ngFor内部的函数

如何在Angular2中调用ngFor内部的函数
EN

Stack Overflow用户
提问于 2016-09-09 19:32:41
回答 1查看 7.7K关注 0票数 0

我试图在*ngfor中调用一个函数,但它重复了数据绑定。如何在ngfor循环中调用函数?

我的视图product.html

代码语言:javascript
复制
       <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文件

代码语言:javascript
复制
GetProductQuanityByCustomer(productId:number)
{ 
    this._productservice.GetProductQuantityByCustomer( productId,122 ).subscribe( p=>this.productQuantity=p )
    return this.productQuantity;
}
EN

回答 1

Stack Overflow用户

发布于 2016-09-09 19:51:27

我将从代码中调用它,并将其赋给组件中的一个变量。

代码语言:javascript
复制
productQuantity: number = 0;
.
.
.

productQuantity = GetProductQuanityByCustomer(number)

但根据https://angular.io/docs/ts/latest/guide/template-syntax.html的说法。您可以使用表达式:

代码语言:javascript
复制
{{GetProductQuanityByCustomer(product.id)}}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39410637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档