0

I have the following HTML template:

<form #topping (change)="updateTopping(topping)">
    <span *ngFor= "let top of toppingOptions">
        {{top.name}} 
        {{top.price.toFixed(2)}}
        <button type="button" value="{{top.name}}-add" (click)="addTopping({{top.name}})">+</button>
        <button type="button" value="{{top.name}}-minus" (click)="minusTopping({{top.name}})">-</button>
        <br>
    </span>    
</form>

As you can probably tell the error occurs in the Button tag. I want to pass "top.name" into addTopping() and minusTopping(), but don't know the correct way of doing so.

Thanks in advance.

1 Answer 1

3

remove the curly brackets and pass the parameter to (click) function

 <button type="button" value="{{top.name}}-add" (click)="addTopping(top.name)">+</button>
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you! Say if I wanted to pass in the actual value attribute, how would I do that? So if value="Bacon-add", how would i pass the value attribute directly into my (click)="addTopping(valueAttribute)" parameter?
try this (click)="addTopping(top.name + '-add')">
Thank you, I'm new to typescript. I just realized how dumb of a question that was..
hehe don't beat yourself up. :D

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.