简体   繁体   English

无法刷新Angularjs中的ng-repeat

[英]Cannot refresh the ng-repeat in Angularjs

I am trying to use a function to check all checkboxes in a tree of checkboxes. 我正在尝试使用一种功能来检查复选框树中的所有复选框。 It is successfully checking and unchecking, BUT if I select a single checkbox then press check all, and uncheck, the single checkbox stays as it is as freeze 它已成功选中和取消选中,但是如果我选中一个复选框,然后按全部选中,然后取消选中,单个复选框将保持冻结状态

HTML HTML

<fieldset id="field3">
  <table>
    <tr ng-repeat="e in empdepts | groupBy:'dep_LDesc'">
      <td>
        <label ng-click="showContent = !showContent"></label>
        <details ng-open="showContent">
          <summary>
            <input type="checkbox" ng-model="chk" /> {{e[0].dep_LDesc}}</summary>
          <div ng-repeat="employee in e">
            <input type="checkbox" ng-checked="chk"> {{employee.Sname}}
          </div>
        </details>
      </td>
    </tr>
  </table>
  <hr />
  <table>
    <tr>
      <td>
        <input type="checkbox" ng-model="all" ng-click="selectall(all)" /> All Departments</td>
    </tr>
    <tr>
      <td>
        <input type="checkbox" ng-model="self" /> Self Services </td>
    </tr>
  </table>
</fieldset>

Controller 调节器

$scope.selectall = function (all) {
    if (all) {
        $scope.chk = true;
    }
    else
    {
        $scope.chk = false;
    }
}

LoadEmpDepts();

function LoadEmpDepts() {
    Assignments.getempdepts().then(function (response) {
        $scope.empdepts = (response.data);
        console.log($scope.empdepts);
    })
}

在此处输入图片说明

You need to have the checked property for individual elements, so the option would be to have a checked property inside each element of the array. 您需要具有单个元素的checked属性,因此选项将是在数组的每个元素内具有一个checked属性。

so whenever checkbox is checked update the property. 因此,每当选中此复选框时,都会更新属性。 and when checking all you make all elements checked property to be true. 当检查所有元素时,使所有元素的checked属性为true。

  <label for="{{all.type}}"  ng-if="x.type === 'ALL'" >{{x.type}}</label>

example, 例,

DEMO DEMO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM