I have a select
dropdown. Upon selecting each value in dropdown, checkboxes are created using ng-repeat
. All the values in the dropdown are supposed to be selected and corresponding checkboxes must be checked and stored in an array.
Whenever a checkbox changes I add it or remove it from array. When I change the dropdown, the checkboxes checked for previous dropdowns are gone.
How do I keep them checked based on the array that stores the checked 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'"
//tried this but selctedFlats 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
is the array of checked values.
I could have done ng-checked="userEventData.selectedFlats.indexOf(sFlats[$index])"
but selectedFlats
contains object. I want to check with a value in the object