I have two arrays: one containing a list of all office locations, and another with user-selected offices. My goal is to display all the office locations and have the checkboxes checked if they match those in the selected list. Here is how I accomplished this:
Code
<div *ngFor="let item of officeLIST">
<div *ngFor="let officeDATA of allOffice.office">
<div *ngIf="item.office_id == officeDATA.office_id">
<input #officeArray type="checkbox" id="officeArray" name="officeArray" class="form-control" value="{{item.officename}}"
checked> {{(item.officename == "" ? "--No data--" : item.officename)}}
</div>
<div *ngIf="item.office_id != officeDATA.office_id">
<input #officeArray type="checkbox" id="officeArray" name="officeArray" class="form-control" value="{{item.officename}}"> {{(item.officename == "" ? "--No data--" : item.officename)}}
</div>
</div>
</div>
Result:https://i.sstatic.net/v3cjr.png
My officeLIST
this.officeLIST = [
{ "office_id": "1", "officename": "Sun Dept" },
{ "office_id": "2", "officename": "Moon" },
{ "office_id": "3", "officename": "Stars" }
]
allOffice.office array
"office": [
{
"office_id": "1",
"officename": "Sun Dept"
},
{
"office_id": "2",
"officename": "Moon Dept"
}
]