How can I get all the selected objects of Checkboxes in AngularJS?

前端 未结 1 1401
失恋的感觉
失恋的感觉 2020-12-30 16:53

I want to get all the selected objects of the checkboxes using AngularJS.

Below is my code

My view.tpl.html



        
相关标签:
1条回答
  • 2020-12-30 17:21

    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 讨论(0)
提交回复
热议问题