0

I am trying to select all toggle buttons exactly like checkboxes select all.

I am using bootstrap4-toggle library

This is my ArrayList

$scope.checkboxes = [ 
    {name:'check[]', value:"1", label: "This is Item 1", selected : false}, 
    {name:'check[]', value:"2", label: "This is Item 2", selected : false}, 
    {name:'check[]', value:"3", label: "This is Item 3", selected : false}, 
    {name:'check[]', value:"4", label: "This is Item 4", selected : false}
];

Select all method

    $scope.toggleSelect = function () {
    angular.forEach($scope.checkboxes, function (item) {
        item.selected = event.target.checked;
        console.log( item.selected= event.target.checked);
    });
}

View

 <input type="checkbox" ng-click="toggleSelect()" /> Select All
  <br />
  <div ng-repeat="checkbox in checkboxes">
   <input type="checkbox" name="{{checkbox.name}}" data-toggle="toggle" data-onstyle="success" data-offstyle="danger" value="{{checkbox.value}}"
    ng-model="checkbox.selected">
   </div>

In the console, I got true value but the toggle button is not switched on

4
  • seems like other issue: plnkr.co/edit/TjTYWOl95HVn34AB Commented Jan 19, 2022 at 12:36
  • I am using bootstrap4-toggle to display the switch button. Commented Jan 19, 2022 at 13:42
  • Where is event defined in your Select All method? Commented Jan 19, 2022 at 13:49
  • event.target.checked get the true value when select all click Commented Jan 19, 2022 at 14:00

0

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.