ng-model checkbox to array

by jacobwsmith

HTML

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<h1>Setting to Data Example</h1>
<div ng-controller="MyCtrl">
    {{answers}}
    <hr/>
    {{value}}
    <hr/>
    <ul>
        <li ng-repeat="item in answers">
            <label>
                <input type="checkbox" ng-model="value[item.value]"> 
                 {{item.text}}
            </label>
        </li>
    </ul>
</div>

JavaScript

var app=angular.module('myApp', []);

function MyCtrl($scope) {
    
    $scope.value = {
        '1': true,
        '2': false,
        '3': true
    };
    $scope.answers = [{
        text: 'One',
        value: '1'
    },{
        text: 'Two',
        value: '2'
    },{
        text: 'Three',
        value: '3'
    }];
    
}