I have an array like following:
hobbies: any= [
{'hobby': 'Sport', 'selected': false},
{'hobby': 'Music', 'selected': false},
{'hobby': 'Reading', 'selected': false},
{'hobby': 'Travelling', 'selected': false},
{'hobby': 'Movies', 'selected': false},
{'hobby': 'Cooking', 'selected': false},
]
I iterate over this array in my template:
<span style="float: left; width: 100px;"><h5>Hobbies</h5></span>
<div class="mdl-grid">
<div *ngFor="let chunk of hobbies | chunks: 2" class="mdl-cell mdl-cell--4-col">
<label *ngFor="let hobby of chunk | values" #checkbox class="mdl-checkbox mdl-js-checkbox">
<input type="checkbox" name="hobbies" [value]="hobby"
[(ngModel)]="hobby.selected" (change)="populateTest(hobby, $event.target.checked)" class="mdl-checkbox__input">
<span class="mdl-checkbox__label">{{hobby.hobby}}</span>
</label>
</div>
</div>
What I want to do is: whichever values user checks those objects should accordingly be updated in hobbbies[] array (right now I simply push them into another array).
If any values are already marked as selected:true in hobbies[], then checkmarks should already be shown in my template.
How can I achieve this?