属性:
参数名称 | 参数类型 | 描述 |
---|---|---|
ngModel | string | 绑定的数据 |
name (optional) | string | 名称 |
ngTrueValue (optional) | expression | 选中的值 |
ngFalseValue (optional) | expression | 未选中的值 |
ngChange (optional) | string | 值改变时触发事件 |
例子:
效果演示<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="checkboxExample">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>input[checkbox]例子</title>
<script src="../angular-1.3.0.14/angular.js"></script>
<script type="text/javascript">
angular.module('checkboxExample', [])
.controller('ExampleController', ['$scope', function ($scope) {
$scope.value1 = true;
$scope.value2 = 'YES'
}]);
</script>
</head>
<body>
<form name="myForm" ng-controller="ExampleController">
Value1: <input type="checkbox" ng-model="value1"> <br />
Value2: <input type="checkbox" ng-model="value2"
ng-true-value="'YES'" ng-false-value="'NO'"> <br />
<tt>value1 = {{value1}}</tt><br />
<tt>value2 = {{value2}}</tt><br />
</form>
</body>
</html>