Skip to content Skip to sidebar Skip to footer

How To Initialize Checkbox From Hashmap (angular 2)

How can we initialize and manipulate a check box value? I've looked at quite a number of examples, but haven't been able to get any to work. I'm trying to present a N x M table wh

Solution 1:

This is fairly trivial as we're just going to bind straight to the assigned object, since we're using JavaScript's bracket property accessor we also get a free dynamic instantiation of the property through the template (dirty, maybe, but powerful). Additionally, wherever you're processing this later assume that a missing value is false:

template

<tr *ngFor="let t of tasks"><td>Task Name for task... {{t.taskName}}&nbsp;&nbsp;</td><td *ngFor="let s of students"><inputtype="checkbox"name="{{t.taskId}}_{{s.studentId}}" [(ngModel)]="assigned[t.taskId + '_' + s.studentId]"></td></tr>

Here's a plunker to demonstrate: http://plnkr.co/edit/9RorhJnv42cCJanWb80L?p=preview

Post a Comment for "How To Initialize Checkbox From Hashmap (angular 2)"