3

This is my component.html, Here I want to get value from numberQuantity input field and pass it to (click) function and use in service function "removeProduct".

<input #numberQuantity type="string" name="quant" id="numberQuantity" >

                <button (click)="removeProduct(user, numberQuantity.value)">Remove quantity</button> 

This is my part of cart.service code

async removeProduct(productData, value){
var removeItem;
 console.log(value);
 removeItem = productData['quantity'];
 removeItem = removeItem -value;
1
  • 2
    What are you trying should work. What's the issue with it? Commented Jan 22, 2020 at 16:12

1 Answer 1

3

Try using ngModel to the text field, where we can access the value directly in component ts file with out sending from html.

.html

In html, you mentioned input type="string", change it to input type="text"

<input #numberQuantity type="text" name="quant" id="numberQuantity" [(ngModel)]="quantityValue" >
<button (click)="removeProduct(user)">Remove quantity</button> 

.ts

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.
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.