select all checkboxes with angular JS

后端 未结 4 2178
不思量自难忘°
不思量自难忘° 2020-12-21 02:22

I am trying to select all checkboxes with one single checkbox. But how to do that?

This is my HTML:

    

        
4条回答
  •  青春惊慌失措
    2020-12-21 02:51

    Here is a JSFiddle you can use ng-checked with a variable on it like user.checked (or use the user.select as you want)

    {{user.id}} {{user.name}} {{user.select}}

    JS:

    var app = angular.module("app", []);
    app.controller('dummy', function($scope) {
      $scope.users = [{
        id: 1,
        name: "Hello",
        select: 1
      }, {
        id: 2,
        name: "World",
        select: 1
      }, ];
      $scope.checkAll = function() {
        angular.forEach($scope.users, function(user) {
          user.checked = 1;
        });
      }
    });
    

提交回复
热议问题