0

如果我的 ng-repeat 上没有选中复选框,我需要禁用一个按钮。

<button class="" data-toggle="modal" data-target="#rejectModal" contenteditable="false" id="delbutton" ng-model="delbutton" ng-disabled="!item.checked">

我的复选框是这样的

<input type="checkbox" name="select" value="checked" ng-model="item.checked"/>

我怎么可能做到这一点?

4

1 回答 1

2

这是您问题的解决方案。[ https://plnkr.co/edit/AIrKVLedt6mcggvpmJE2?p=preview][1]

控制器:

app.controller('MainCtrl', function($scope) {

  $scope.Items = [
    {checked:false},
  {checked:true},
  {checked:false},
  ];

  $scope.setButtonEnabled = function(itemchecked){
      var isButtonEnabled =false;
      angular.forEach( $scope.Items, function(item){
        if(item && item.checked)
           isButtonEnabled = true;
      });
      return  isButtonEnabled;
  };
});

html:

<div ng-repeat="item in Items">
      <input type="checkbox" name="select" value="checked" ng-model="item.checked" ng-change="setButtonEnabled()" />
    </div>
    <br>
    <button  id="delbutton"  ng-disabled="setButtonEnabled()">Submit</button>
于 2018-02-12T03:00:58.663 回答