摘要:ng-click()捉checkbox值為undefined,改用ng-change()即可
<input type="checkbox" ng-click="click()" ng-model="model.value1">
alert($scope.ChkWait1); ->undefined
alert($scope.ChkWait1); ->undefined
改用data-ng-change="chkWaitClick()" data-ng-model="model.ChkWait1"
另外先對model = {value1:true}先給預設值才行!!
----------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-checkbox-input-directive-production</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
</head>
<body ng-app="checkboxExample">
<script>
angular.module('checkboxExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.model = {
value1: true,
value2: 'YES'
}
}]);
</script>
<form name="myForm" ng-controller="ExampleController">
Value1: <input type="checkbox" ng-model="model.value1"> <br/>
Value2: <input type="checkbox" ng-model="model.value2"
ng-true-value="YES" ng-false-value="NO"> <br/>
<tt>value1 = {{model.value1}}</tt><br/>
<tt>value2 = {{model.value2}}</tt><br/>
</form>
</body>
</html>