Javascript 如何将输入标记值传递给(单击)函数并在服务中使用
这是我的component.html,我想从numberQuantity输入字段中获取值,并将其传递给(单击)函数,并在服务函数“removeProduct”中使用Javascript 如何将输入标记值传递给(单击)函数并在服务中使用,javascript,html,angular,angular8,Javascript,Html,Angular,Angular8,这是我的component.html,我想从numberQuantity输入字段中获取值,并将其传递给(单击)函数,并在服务函数“removeProduct”中使用 尝试在文本字段中使用ngModel,在这里我们可以直接访问组件ts文件中的值,而无需从html发送 .html 在html中,您提到了input type=“string”,将其更改为input type=“text” 你所尝试的应该是有效的。有什么问题吗? <input #numberQuantity type="strin
尝试在文本字段中使用ngModel,在这里我们可以直接访问组件ts文件中的值,而无需从html发送 .html 在html中,您提到了input type=“string”,将其更改为input type=“text”
你所尝试的应该是有效的。有什么问题吗?
<input #numberQuantity type="string" name="quant" id="numberQuantity" >
<button (click)="removeProduct(user, numberQuantity.value)">Remove quantity</button>
async removeProduct(productData, value){
var removeItem;
console.log(value);
removeItem = productData['quantity'];
removeItem = removeItem -value;
<input #numberQuantity type="text" name="quant" id="numberQuantity" [(ngModel)]="quantityValue" >
<button (click)="removeProduct(user)">Remove quantity</button>
quantityValue: string;
removeProduct(user) {
console.log(this.quantityValue); // we can access quantityValue here since it is declared as ngModel in html
...
...
// We can call a method in service from here by sending this.quantityValue to service method.
}