单击按钮时如何获取输入数值
how to get input number value when button is clicked
我不确定如何获取按钮的值...这是我的代码
<p *ngFor = "let product of ProductsDetails; let i = index">
<input type="number" value={{cartProducts[i].amount}} class="quantInput">
<button mat-raised-button color="primary" class="changeBTN">change</button>
</p>
注意:按钮和输入的数量是动态的,所以我不能有一个变量来保存输入的值,或者我只是不知道该怎么做
<p *ngFor = "let product of ProductsDetails; let i = index">
<input type="number" [(ngModel)]="values[i]" value={{cartProducts[i].amount}} class="quantInput">
<button mat-raised-button color="primary" class="changeBTN" (click)="doSomethingWithInputValue(i)" >change</button>
</p>
ts 文件
values: any[];
//initialize array when you have loaded productDetails
ProductDetails.forEach((productDetail) => {
this.values.push({});
});
public doSomethingWithInputValue(index){
const currentInputValue = this.values[index];
...do everything you want with this value here
}
我不确定如何获取按钮的值...这是我的代码
<p *ngFor = "let product of ProductsDetails; let i = index">
<input type="number" value={{cartProducts[i].amount}} class="quantInput">
<button mat-raised-button color="primary" class="changeBTN">change</button>
</p>
注意:按钮和输入的数量是动态的,所以我不能有一个变量来保存输入的值,或者我只是不知道该怎么做
<p *ngFor = "let product of ProductsDetails; let i = index">
<input type="number" [(ngModel)]="values[i]" value={{cartProducts[i].amount}} class="quantInput">
<button mat-raised-button color="primary" class="changeBTN" (click)="doSomethingWithInputValue(i)" >change</button>
</p>
ts 文件
values: any[];
//initialize array when you have loaded productDetails
ProductDetails.forEach((productDetail) => {
this.values.push({});
});
public doSomethingWithInputValue(index){
const currentInputValue = this.values[index];
...do everything you want with this value here
}