user6781560
user6781560

Reputation:

checkbox (click) angular 4 on dynamic checkbox creation

So I am dynamically creating checkboxes. What I want is for each checkbox to have a value which is dynamically created. On click of the checkbox I want the values of the checkbox to append to an array.

Here is what I am working on. Am I on track?

<div *ngFor="let cuisine of cuisines"
           class="col-md-10 col-md-offset-2 cuisineinput">

        <input type="checkbox"
               id="{{cuisine.cuisine}}"
               name="{{cuisine.cuisine}}"
               (click)="cuisineappend({{cuisine.cuisine}})"
               > {{cuisine.cuisine}}

      </div> <!--cuisine div -->

now Im getting an complaint on the (click)="cuisineappend({{cuisine.cuisine}})" it doesn't like that I am passing{{cuisine.cuisine}} to the cuisineappend part. How would I pass the value?

Upvotes: 0

Views: 70

Answers (1)

jitender
jitender

Reputation: 10429

It should be

<input type="checkbox"
               id="{{cuisine.cuisine}}"
               name="{{cuisine.cuisine}}"
               (click)="cuisineappend(cuisine.cuisine)"
               >

no need of {{ brackets

Working demo

Upvotes: 1

Related Questions