我想启用提交按钮,当一个或多个复选框的值被选中时,我试着用下面的代码启用它的按钮,但如果我检查一个值,使所有复选框分离?任何想法是什么实施错误?如何基于复选框启用/禁用提交按钮?
main.html中
<tr ng-repeat="user in userList track by $index">
<td st-ratio="20">{{user.attuid}}</td>
<td st-ratio="30">{{user.firstName}} {{user.lastName}}</td>
<td st-ratio="20"><input type="checkbox" ng-model="userList.selected" ng-click="checkedValue(user)"> </td>
</tr>
<button class="btn btn-primary" ng-disabled="user.selected" ng-disabled="!userList.selected" ng-click="addUsers()">Add User(s)</button>
Ctrl.js
$scope.$on('show-user-list',function(e,data){
$scope.userList = data;
$scope.userList.selected = false;
});
$scope.checkedValue = function(user) {
user._id = user.attuid;
user.type = 'user';
if ($scope.selectedUsers.indexOf(user) === -1) {
$scope.selectedUsers.push(user);
$scope.userList.selected = true;
} else {
$scope.selectedUsers.splice($scope.selectedUsers.indexOf(user), 1);
}
console.log($scope.userList.selected);
};
是的,prooblem是'NG-模型= “userList.selected”'我这一点,应该是'ng-model =“user .selected”' –
按钮怎么样? – hussain
更新了答案,并检查了启用和禁用按钮的方法。 –