我想啓用提交按鈕,當一個或多個複選框的值被選中時,我試着用下面的代碼啓用它的按鈕,但如果我檢查一個值,使所有複選框分離?任何想法是什麼實施錯誤?如何基於複選框啓用/禁用提交按鈕?
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
更新了答案,並檢查了啓用和禁用按鈕的方法。 –