如何在In Angular 4中设置内部文本字段的默认值? [英] How to set default value for a textfield inside for In Angular 4?
本文介绍了如何在In Angular 4中设置内部文本字段的默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个for循环,在其中显示所选的产品名称和价格.用户可以选择输入数量,但默认情况下,数量应为1.如何设置默认值为1的文本字段值.
I have a for loop where I am showing the selected product name and price. The user has an option to enter the quantity but by default, the quantity should be 1. How I can set the text field value with a default value of 1.
我尝试了以下方法,但是没有用:
I have tried the following way but it's not working:
<tr *ngFor="let spro of selectedProd;let i = index;">
<td data-title="Product Name">{{spro.product_description}}</td>
<td data-title="Unit Price" class="numeric">
<i class="fa fa-inr"></i>2000</td>
<td data-title="Qty" class="numeric">
<input type="text" [(ngModel)]="selectedProd[i].qty" name="qty" value="1">
</td>
<td data-title="Total Price" class="numeric">
<i class="fa fa-inr"></i>{{selectedProd[i].qty*2000}}</td>
</tr>
推荐答案
使用value
放在方括号中:
[value]="myDefaultValue"
在组件中:
myDefaultValue: number = 1;
或使用一种方式绑定:
<input type="text" (ngModelChange)="selectedProd[i].qty" name="qty" value="1">
这篇关于如何在In Angular 4中设置内部文本字段的默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文