1

I am creating a app in angularjs. I have problem while showing all checkbox selected when page open.

here is my code:

<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>

Here is my js code:

$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;
        });

    }

On click of button all checkboxes selected(this is working),but I want when page is open then all checkboxes should be selected.

2

1 Answer 1

1

you can do it in controller before template load

 $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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.