Due to various conflicts and dependencies, I have opted to use AngularJS 1.5.x instead of 1.6.x, which has led me to encounter some issues with ng-checked functionality.
Within my ng-repeat
loop, I am dealing with 2 objects:
- vm.stateList, containing all 50 states
- vm.pager, a JSON object where selected states are listed
My goal is to display all states as checkboxes and have them pre-checked if they exist in the vm.pager object.
div ng-repeat="states in vm.statesList"
Here is the code snippet for the checkbox that should be checked if the state is found in my object:
<input ng-model="vm.pager.location[$index].state" type="checkbox" id="state{{states}}">{{states.name}}
Below is an example of the data structure, highlighting the presence of the state in the location:
{
"Id": 105,
"Name": "blah",
"Description": "other data",
"$$hashKey": "object:98",
"location": [
{
"Id": 96,
"state": "NY",
"Order": 9,
}
]
}