How can i simply add and remove checked attribute to check-box using angularjs. I've find solution from this question,but it requires Jquery

如何使用angularjs简单地添加和删除选中的属性到复选框。我从这个问题找到解决方案,但它需要Jquery

Is any other way to do this without using Jquery?

没有使用Jquery,还有其他方法吗?

Here is what i am tried

这是我的尝试

<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="";
  }
}

But the removing wont work

但删除不会工作

4 个解决方案

#1


6

This is Angularjs recommended way of check and un check checkbox

这是Angularjs推荐的check and un check复选框

HTML : <input type="checkbox" ng-model="checkVal" ng-true-value="true" ng-false-value="false">

HTML:

Also works

<input type="checkbox" ng-checked="checkVal">

JS :

module.controller('settingsCtrl',function($scope){
  //for adding
  $scope.checkVal=true;
  //for removing checkbox
  $scope.test=function(){
   $scope.checkVal=false;
  }
}

更多相关文章

  1. HTML5 数据集属性dataset
  2. 浏览器如何处理HTML元素上的无效/未指定的属性?
  3. Javascript学习:案例7--对象属性和方法的遍历、删除、添加.html
  4. javascript 构造函数中的属性与原型上属性优先级的比较
  5. 在jQuery中使用css transform属性
  6. javascript的offset、client、scroll使用方法,相关属性解释原理
  7. 如何将javascript set style属性返回到CSS默认值
  8. 对象的属性也要加引号吗
  9. javascript中的属性类型

随机推荐

  1. python3使用 openpyxl 操作excel表格
  2. Python基础数据类型-函数传参详解
  3. Python—插入排序算法
  4. 2D Numpy Array的边缘值
  5. 学习python的第十六天(迭代器,三元表达式,
  6. python 装饰器和 functools 模块
  7. python新式类删改查
  8. [LeetCode] 244. Shortest Word Distance
  9. 解决SimpleCV的Hello World程序无法显示
  10. Python 2.6.2中的ElementTree处理指令支