【问题标题】:Default Select all checkboxes in angularjs默认选择angularjs中的所有复选框
【发布时间】:2016-09-03 18:41:36
【问题描述】:

我正在用 angularjs 创建一个应用程序。在页面打开时显示所有选中的复选框时出现问题。

这是我的代码:

<div class="check_box">
<input type="checkbox" id="checkbox1" name="checkbox" ng-model="selectedAllStatus" ng-click="checkAllTypes()">
<label for="checkbox1"><span for="checkbox1">All</span></label>
</div>
</li>

<li ng-repeat="customersFlowsList in customersFlows | unique:'type'" ng-init="checkAllTypes()">

<div class="check_box">
<input type="checkbox" id="checkbox1" name="checkbox"  ng-model="filter[customersFlowsList.type]">
<label for="checkbox1"><span for="checkbox1">{{customersFlowsList.type | customerType}}</span></label>
</div>
</li>

这是我的js代码:

$scope.checkAllStatus = function()
    {
       console.log($scope.selectedAll)
        if ($scope.selectedAll) {
            $scope.selectedAll = true;
        } else {
            $scope.selectedAll = false;
        }
        angular.forEach($scope.customersFlows, function (customersFlowsList) {
           $scope.filterLink[customersFlowsList.linkStatus] = $scope.selectedAll;
        });

    }

单击按钮时,所有复选框都被选中(这是有效的),但我希望当页面打开时,所有复选框都应该被选中。

【问题讨论】:

标签: javascript angularjs


【解决方案1】:

您可以在模板加载之前在控制器中执行此操作

 $scope.checkAllStatus = function() {
   console.log($scope.selectedAll)
   if ($scope.selectedAll) {
     $scope.selectedAll = true;
   } else {
     $scope.selectedAll = false;
   }
   angular.forEach($scope.customersFlows, function(customersFlowsList)         {
     $scope.filterLink[customersFlowsList.linkStatus] = $scope.selectedAll;
   });

 }


  $scope.selectedAllStatus = true;
  $scope.checkAllStatus()

【讨论】:

    猜你喜欢
    • 2015-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-26
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    相关资源
    最近更新 更多