[英]how to obtain the value of an input field in an *ngFor loop?
I need to obtain values from a series of inputs in an *ngFor loop. 我需要从* ngFor循环中的一系列输入中获取值。 I tried using the name "(change)=addQty(qty,i)" I tried 2way binding but all the inputs ended up with the same value. 我尝试使用名称“(change)= addQty(qty,i)”,尝试2way绑定,但所有输入最终都具有相同的值。 I tried searching Google. 我尝试搜索Google。 In the code that follows I have stripped out some non-related code and classes. 在下面的代码中,我删除了一些不相关的代码和类。
<div *ngFor='let meal of meals; let i = index'>
<div>
<span>
{{meal.mealName}}  
<mat-icon>thumb_up</mat-icon> {{meal.dislike}}
<mat-icon>thumb_down</mat-icon>{{meal.like}}
</span>
</div>
<br>
<div>
{{meal.mealDesc}}
<br> Price: {{meal.price1 | currency}}   Qty:
<input class='number' type='number' name='qty' min=0 (change)=addQty(i)>
</div>
</div>
If it is something simple I will be so embarrassed. 如果这很简单,我会很尴尬。
您没有将change
事件的值传递回控制器,而是将addQty($event, i)
更改为addQty($event, i)
,在控制器addQty(e, i)
为e.target.data
或e.target.value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.