angularjs-如何取消选中按钮的复选框

时间:2019-01-03 17:35:34

标签: html angularjs

我有一些复选框来自angularjs中的循环。在这里,我需要取消选中单击按钮的所有复选框。在这里我已经尝试过了,但是没有用,有人可以帮我吗。这是下面的代码

HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <div ng-app="myApp" ng-controller="myCtrl">
    <ul ng-repeat="(x, y) in items.filter">
    <li class="parent"><b>{{x}}</b></li>
    <li class="child">
    <ul>
    <li ng-repeat="p in y.value"><input type="checkbox" ng-model="vehicle" name="vehicle">{{p}}</li>
    </ul>
    </li>
    </ul>
    <button ng-click="myFunct()" type="button">click</button> 
    </div>

脚本

var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope,$http) {   
$scope.items = {"filter":{"Category1":{"value":["one","two","three"]},"Category2":{"value":["four","five","six"]}}} 
    $scope.myFunct = function() {
  $scope.vehicle="";
    }
    });

2 个答案:

答案 0 :(得分:0)

将ng-checked与ng-click结合使用是从控制器控制复选框的最佳解决方案,您可以尝试以下方法:

<ul ng-repeat="(x, y) in items.filter">
    <li class="parent"><b>{{x}}</b></li>
    <li class="child">
    <ul>
    <li ng-repeat="p in y.value">
      <input type="checkbox" 
      ng-checked="v"
      name="Item.selected">{{p}}</li>
    </ul>
    </li>
    </ul>
 <input type="checkbox" ng-model="v" ng-click="checkAll()" />Clear all

示例:http://next.plnkr.co/edit/a9DInByf8a6yv6wl?preview

希望有帮助!

答案 1 :(得分:0)

分配 $ scope.vechicle = false

更新代码

K