I am working with a select
dropdown that creates checkboxes using ng-repeat
based on the selected value. The goal is to have all values in the dropdown selected, corresponding checkboxes checked, and store them in an array.
Each time a checkbox is changed, it should be added or removed from the array. However, switching to a different dropdown option clears the checked checkboxes from previous selections.
How can I keep the checkboxes checked based on the array that holds the selected values?
<div ng-repeat="flat in flatsArray" class="row" style="width:90%;">
<div class="col-md-2">
<input
type="checkbox" ng-true-value="{{flat.flat_id}}"
ng-false-value="'-1'"
//I attempted this but selectedFlats is an object
ng-checked="userEventData.selectedFlats.indexOf(sFlats[$index])" `userEventData.selectedFlats` is an object
ng-change="checkChanged(sFlats[$index], flat)"
ng-model="sFlats[$index]" />
</div>
<div class="col-md-10"><label for="{{flat.flat_no}}">{{flat.flat_no}}</label></div>
</div>
$scope.userEventData.selectedFlats
keeps track of the checked values in an array.
I considered using
ng-checked="userEventData.selectedFlats.indexOf(sFlats[$index])"
but since selectedFlats
is an object, I need to check with a value inside the object instead.