I want to get all the selected objects of the checkboxes using AngularJS.
Below is my code
My view.tpl.html
-
If I understand correctly you want to create a checkbox and dynamically bind it to an item(s) from a list, if so this is how I would go about doing it:
$scope.modelContainer=[];
angular.forEach($scope.itemList,function(item){
$scope.modelContainer.push({item:item,checked:false });
});
HTML:
<div ng-repeat="item in itemList">
{{item.name}}
<input type="checkbox" ng-click="selected(item.id)" ng-model="modelContainer[$index].checked" />
</div>
See plunk. See the model container change in the console whenever you check a checkbox.
讨论(0)
- 热议问题