samedi 7 mai 2016

Checkboxes list in Angular 1.5 with one name/model

How to set dynamically list of checkboxes. It seems that what worked in older versions described here doesn't work in angular 1.5.

<div ng-repeat="item in items">
     <input type="checkbox" ng-model="cars[item.id]"  ng-value="" ng-checked="item.checked == '1'"> 
</div>
$scope.items = [{id:'1', car:'opel', checked:'1'},
               {id:'2', car:'fiat', checked:'1'},
               {id:'3', car:'ford', checked:'0'}];

This loop doesn't work correctly, I didn't get ng-model="cars[1]", ng-model="cars[2]", etc but is ng-model="cars[item.id]"

What I need is dynamically generate list of checkboxes and receive actual state of checked checkboxes:

cars = $scope.cars; //this should return [1, 2]

Aucun commentaire:

Enregistrer un commentaire