Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将输入标记值传递给(单击)函数并在服务中使用_Javascript_Html_Angular_Angular8 - Fatal编程技术网

Javascript 如何将输入标记值传递给(单击)函数并在服务中使用

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

这是我的component.html,我想从numberQuantity输入字段中获取值,并将其传递给(单击)函数,并在服务函数“removeProduct”中使用


尝试在文本字段中使用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.
}