Rushi Patel
Rushi Patel

Reputation: 601

Angular 5 Checkbox in *ngFor Loop and get check and unchecked particular checkbox

Any Idea in Angular 5 where I have the checkbox in *ngFor loop so I want to know how this is getting the change in check and uncheck for the particular checkbox in *ngFor.

I have some code as below

<tr *ngFor="let addon of group?.item_addons; let i = index;">
   <td>
       <div class="form-check">
         <label class="form-check-label">
           <input class="form-check-input" type="checkbox" 
           (change)="onselectAddon(addon,$event,group,i)">
           <span class="form-check-sign"></span>
              {{addon.addons_name}}
         </label>
        <span class="float-right">+ {{addon.addons_price}}</span>
       </div>                                                                            
   </td>
</tr>

I want to get selected and unselected value from particular checkbox.

Upvotes: 0

Views: 1415

Answers (1)

Robdll
Robdll

Reputation: 6263

you can simply add to your input the following:

[checked]="someExpression"

if you prefer, you could call a function where you pass the current addon like

[checked]="isChecked(addon)"

Upvotes: 1

Related Questions