I have a JSON object which I am repeating with ng-repeat, the keys are strings, and the values are an array. I am listing each of the values as a checkbox. I would like to create a second object which contains a list of only the checkboxes that are checked. I want to preserve the structure of the object with keys and values.
I'm unsure how to bind this to a model properly so that the structure is preserved.
This is my HTML
<h3 >Dynamic data binding in AngularJS</h3>
<div ng-app ng-controller=Controller class=container>
<h4>Inputs</h4>
<ul ng-repeat=(parent, values) in inputs>
<span>{{parent}} : </span>
<li ng-repeat=value in values><label>{{value}}
<input type=checkbox ng-model=output[parent] ng-checked=output[parent] value=value >
</input></label>
</li>
</ul>
<h4>Outputs</h4>
<ul ng-repeat=(key,value) in inputs>
<li>
{{key}} : {{output[key]}}
</li>
</ul>
</div>
and my JS
function Controller($scope) {
$scope.output = {};
$scope.inputs = {'category': ['one','two','three'], 'color':['blue','green']};
}
Is there some simple way to do this? I have the feeling that I'm missing something minor and this will all work nicely.