AngularJs checkbox绑定
来源:互联网 发布:网络性能评测指标 编辑:程序博客网 时间:2024/06/05 05:00
一、AngularJs中关于checkbox的双向绑定
<input type="radio" ng-model="string" value="string" [name="string"] [ng-change="string"] ng-value="string">
1.默认ng-model绑定返回的都是true或false
选择分类: <label > <input type="checkbox" ng-model='type' ng-change='changeValue();' name="" value="1">第一分类 </label> <label > <input type="checkbox" ng-model='type' ng-change='changeValue();' name="" value="2">第二分类 </label> <label > <input type="checkbox" ng-model='type' ng-change='changeValue();' name="" value="3">第三分类 </label>type:{{type}} <script> (function() { 'use strict'; var app= angular.module('module', [ ]); app.controller('myCtrl',function($scope){ }); })(); </script>
2.可以只用ng-true-value,ng-false-value,分别指定选中和不选中ng-model的值
选择分类: <label > <input type="checkbox" ng-model='type.first' ng-true-value='1' ng-false-value="" name="type" >第一分类 </label> <label > <input type="checkbox" ng-model='type.second' ng-true-value='2' ng-false-value="" name="type" >第二分类 </label> <label > <input type="checkbox" ng-model='type.thrid' ng-true-value='3' ng-false-value="" name="type" >第三分类 </label><br/>type:{{type}}
3.如果想把所有选中的结果,使用逗号隔开,处理方式1如下:
选择分类: <label > <input type="checkbox" ng-model='type[0]' ng-true-value='1' ng-change='change1();' ng-false-value="" name="type" >第一分类 </label> <label > <input type="checkbox" ng-model='type[1]' ng-true-value='2' ng-change='change1();' ng-false-value="" name="type" >第二分类 </label> <label > <input type="checkbox" ng-model='type[2]' ng-true-value='3' ng-change='change1();' ng-false-value="" name="type" >第三分类 </label><br/>type:{{type}}
初始化绑定+获取选中结果:
(function() { 'use strict'; var app= angular.module('module', [ ]); app.controller('myCtrl',function($scope){ $scope.change1=function(){ var array=[]; for(var item in $scope.type){ if($scope.type[item]) array.push($scope.type[item]); } console.info(array); } //初始化绑定 $scope.type=[1,2]; }); })();
更多参考:
使用$watch来监视属性或对象的变化
AngularJs select绑定数字类型问题
AngularJS路由之ui-router(三)大小写处理
0 0
- angularjs checkbox双向绑定
- AngularJs checkbox绑定
- angularJS CheckBox 绑定值
- AngularJS中checkbox是否选中的绑定变量问题
- angularJS checkbox
- angularjs checkbox
- angularjs 如何处理checkbox
- Angularjs中checkbox使用
- Table Multiple checkbox AngularJS
- angularjs之checkbox
- angularjs之checkbox全选
- angularJS用于radio、checkbox
- GridView中的CheckBox绑定
- AngularJs数据绑定原理
- angularjs 双向绑定
- AngularJS例子 数据绑定
- angularjs绑定调用时间
- angularJs<一、数据绑定>
- Java synchronized关键字用法(清晰易懂)
- Android Studio 安装应用失败总结
- 设计模式之观察者模式
- ssh框架项目下的购物车模块
- c++ prime 课后题 文本查询程序
- AngularJs checkbox绑定
- Find All Numbers Disappeared in an Array
- 网络深度教学
- AngularJS基础讲解-语法入门02
- Unity总结:优化Draw Calls
- 小程序tabbar跳转
- Java基本概念-自定义标签
- 排序组件
- LVS 集群负载均衡实战