Because of some other conflicts and dependencies , i'm not using angularjs 1.6.x , i'm using 1.5.x so i'm not sure if there is some bug - but I just know ng-checked is just awful
So I have ng-repeat
2 objects
Thus I'm looping through displaying all the states as checkboxes, but I WANT to set them to be CHECKED - if they are found in my vm.pager object
div ng-repeat="states in vm.statesList"
checkbox I want checked if in my object
<input ng-model="vm.pager.location[$index].state" type="checkbox" id="state{{states}}">{{states.name}}
Example of data
Notice that the state
is found in the location
{
"Id": 105,
"Name": "blah",
"Description": "other data",
"$$hashKey": "object:98",
"location": [
{
"Id": 96,
"state": "NY",
"Order": 9,
}
]
}
You could make a function in your controller that is called from each checkbox:
<input ng-model="vm.pager.location[$index].state"
type="checkbox" id="state{{states}}"
checked="vm.isInState(states)">{{states.name}}
function isInState(state) {
return vm.pager.findIndex((item) => item.location[0].state === state) > 0 ? true : false;
}