没有检查时禁用按钮AngularJS

时间:2018-08-08 07:12:30

标签: angularjs angular-ngmodel

我只想在选中modelCheck时显示按钮发布,而在disable没什么时显示checked我的代码:HTML: HTML:

  <table>
  <tr>
    <th>name</th>
     <th><button class="btn" ng-if="(modelCheck | json) != ({} | json)" ng-click="post()">post</button></th>
      <th><button class="btn disabled" ng-if="(modelCheck | json) == ({} | json)" ng-click="post()">post</button></th>
  </tr>
  <tr ng-repeat="x in messages">
    <td>{{x.name}}</td>
    <td><input type="checkbox" ng-model="modelCheck[x.name]"/></td>
  </tr>
</table>

JS:

 $scope.modelCheck = {};

  $scope.messages = 
    [
        {
            "name": "eva",
        },
        {
            "name": "ben",
    },
 ];

$scope.post = function(){
    var data = [];
       for (var k in $scope.modelCheck) {
           if ($scope.modelCheck.hasOwnProperty(k) && $scope.modelCheck[k]) {
            data.push({'name': k});
           }
       }
       console.log(data);
       // do with data as you wish from here
    };

我的朋克:http://next.plnkr.co/edit/FudqIFQ1Pe0Vfhvq

感谢您的回答和预先的帮助!

1 个答案:

答案 0 :(得分:1)

您可以使用ng-disabled执行此操作。

for (int p = 0; p < ((list.size()) - 1); p++) {
    int min = p;                 
    count++;

    for(int q=p+1; q<list.size();q++) {
        if(doubleArray[q] < doubleArray[min]) {
            min = q;
        }
    }

    double smallNumber = doubleArray[p];
    doubleArray[p] = doubleArray[min];
    doubleArray[min] = smallNumber;                  
}

和在JavaScript中:

<button class="btn"  ng-disabled="!isSelected()" ng-click="post()">post</button>

Plunker demo。希望这会有所帮助