在angularjs中动态地向复选框添加/移除checked属性
Adding/Removing checked attribute to checkbox dynamiclly in angularjs
如何使用angularjs简单地添加和删除复选框中的checked属性?我已经从这个问题找到了解决方案,但它需要Jquery
有没有其他方法可以做到这一点,而不使用Jquery?
这是我所尝试的
<input type="checkbox" id="test" class="switch__input" checked="{{checkVal}}">
<input type="button" ng-click="test()" value="test">
JS
module.controller('settingsCtrl',function($scope){
//for adding
$scope.checkVal="checked";
//for removing checkbox
$scope.test=function(){
$scope.CheckVal="";
}
}
但是删除不成功
这是Angularjs推荐的选中和取消选中复选框的方式