ng-disabled 不适用于单选按钮和复选框

ng-disabled not working for radio buttons and checkboxes

我正在开发 AngularJS 应用程序。我正在尝试创建一个页面,允许用户 select 三个单选按钮之一。这三个选项中的两个在它们下方也有复选框,允许用户 select 如果他们 select 编辑了适当的单选按钮,则可以选择其他选项。为了防止不正确的复选框 selections,我试图在复选框上设置 ng-disabled 属性。到目前为止,它没有用,我已经尝试了几次不同的迭代。

这是我的 HTML:

    <div class="panel-body">
        <input type="radio" id="notFraudulent" name="actionSelector" ng-model="cleared" /><label for="notFraudulentRadio"> Not Fraudulent</label><br />
        <input type="checkbox" id="highVolumeCustomer" ng-model="highVolumeCustomer" ng-disabled="(fraudulent||cleared)" /><label for="highVolumeCustomer"> High Volume Customer</label><br />
        <br/>
        <input type="radio" id="appearsFraudulent" name="actionSelector" ng-model="fraudulent" /><label for="isFraudulentRadio"> Appears Fraudulent</label><br />
        <input type="checkbox" id="reportAccount" ng-model="reportAccount" ng-disabled="(cleared||reviewed)" /><label for="reportAccount"> Report Account</label><br />
        <br/>
        <input type="radio" id="markReviewed" name="actionSelector" ng-model="reviewed" /><label for="markReviewed"> Mark As Reviewed For Later</label>
    </div>

我曾尝试将 ng-disabled 表达式的运算符更改为 &&,因为我看到一些文章建议运算符并不代表人们认为的意思。但这是行不通的,如果我只在表达式中放置一个条件,它也行不通。控制器中(目前)还没有任何东西尝试使用或操纵 HTML 中的任何 ng-models。我得出的结论是,关于单选按钮,我遗漏了一些东西,但我终究无法弄清楚是什么。

谁能看出我的错误是什么?

你应该使用value 属性为单选按钮绑定特殊值,当单选按钮的状态改变时,该值将保持在ng-model

参考下面的代码片段:

angular.module("app", [])
  .controller("myCtrl", function($scope) {
    $scope.selectedValue = 'cleared';
    $scope.cleared = false;
    $scope.fraudulent = false;
    $scope.reviewed = false;
  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="panel-body" ng-app='app' ng-controller="myCtrl">
  <input type="radio" id="notFraudulentRadio" name="actionSelector" value="cleared" ng-model="selectedValue" /><label for="notFraudulentRadio"> Not Fraudulent</label><br />
  <input type="checkbox" id="highVolumeCustomer" ng-model="highVolumeCustomer" ng-disabled="selectedValue === 'fraudulent' || selectedValue === 'cleared'" /><label for="highVolumeCustomer"> High Volume Customer</label><br />
  <br/>
  <input type="radio" id="isFraudulentRadio" name="actionSelector" value="fraudulent" ng-model="selectedValue"/><label for="isFraudulentRadio"> Appears Fraudulent</label><br />
  <input type="checkbox" id="reportAccount" ng-model="reportAccount" ng-disabled="selectedValue === 'cleared' || selectedValue === 'reviewed'" /><label for="reportAccount"> Report Account</label><br />
  <br/>
  <input type="radio" id="markReviewed" name="actionSelector" value="reviewed" ng-model="selectedValue"/><label for="markReviewed"> Mark As Reviewed For Later</label>
  <br>
  cleared:{{cleared}}<br>
  fraudulent:{{fraudulent}}<br>
  reviewed:{{reviewed}}<br>
  selectedValue: {{selectedValue}}
</div>