A
A
angularest2015-12-30 11:33:54
JavaScript
angularest, 2015-12-30 11:33:54

How to select all checkboxes in angular?

Tell me how in angular when you click the "select all" checkbox, all checkboxes become checked.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Villarou, 2015-12-30
@angularest

Here is the simplest example for you.

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Example - example-checkbox-input-directive-production</title>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
</head>
<body ng-app="checkboxExample">
  <script>
  angular.module('checkboxExample', [])
    .controller('ExampleController', ['$scope', function($scope) {
      $scope.value1 = false;
    }]);
</script>
<form name="myForm" ng-controller="ExampleController">
<input type="checkbox" id="all" ng-model="value1"><label for="all">выделить все</label>
  <input type="checkbox" class="block" ng-checked="value1">
  <input type="checkbox" class="block" ng-checked="value1">
  <input type="checkbox" class="block" ng-checked="value1">
  <input type="checkbox" class="block" ng-checked="value1">
 </form>
</body>
</html>

T
Timofey, 2015-12-30
@mr_T

Делаешь в scope функцию, которая проходится по всем привязанным в ng-model свойствам этих чекбоксов и устанавливает их значения в нужные (true по умолчанию или то, что у тебя в ng-true-value инпута).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question