【发布时间】:2016-11-12 23:57:00
【问题描述】:
我的代码是这样的: html:
<input type="checkbox" ng-model="cb1"> You have discussed the amount, frequency and term applicable to the payment schedule with your customer and they have agreed.
获取复选框值
console.log('checkbox:', $scope.cb1);
结果总是undefined,不管我是否勾选。
但如果我的代码更改为
<input type="checkbox" ng-model="cb1.value"> You have discussed the amount, frequency and term applicable to the payment schedule with your customer and they have agreed.
并初始化变量:
$scope.cb1 = {value: true};
然后我可以得到复选框值
console.log('checkbox:', $scope.cb1.value);
有人能告诉我为什么吗?谢谢
【问题讨论】:
-
console.log('checkbox:", $scope.cb1);是无效的 JavaScript。 -
你能告诉我们控制器代码吗?
-
@VivekSingh 我正在构建一个复杂的应用程序,因此控制器中有一堆代码。但我已经展示了所有相关代码
标签: javascript angularjs checkbox angular-ngmodel