双向绑定动态创建的复选框

时间:2017-11-30 13:23:04

标签: angular

如何使用动态创建的复选框进行双向绑定?

quali=[{class:"10",checked:false},{class:"12",checked:true},{class:"others",checked:true}];


<span *ngFor="let q_list of quali;let i=index" class="lists">
<input type="checkbox" class="checks" name="q_list" [(ngModel)]="q_list.checked">&nbsp;{{q_list.class}}</span>

1 个答案:

答案 0 :(得分:0)

它对你有帮助

var app = angular.module('testApp',[]);
    app.controller('testCtrl',function($scope){
$scope.data=[{id:1,name:"one",check:true},{id:2,name:"two",check:false},{id:3,name:"three",check:true}]
    });
table{
border-collapse:collapse;
width:100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
 <body ng-app="testApp" ng-controller="testCtrl">
    
    <table border="1">
        <tr ng-repeat="d in data">
            <td><input type="checkbox" ng-model="data[$index].check">{{d.id}}</td>
            <td>{{d.name}}</td>
        </tr>
    </table>
 </body>