我有这些单选按钮,但提交时无法获得任何价值。我尝试了完全相同的方法:http://plnkr.co/edit/4lvJclZuh0lryF1nhmdt?p=preview
HTML:
<body ng-controller="ExamCtrl">
<form name="myForm" ng-submit="submitForm()">
<label><input type="radio" name="test" ng-model="radioValue" value="1"/> One</label>
<label><input type="radio" name="test" ng-model="radioValue" value="2"/> Two</label>
<label><input type="radio" name="test" ng-model="radioValue" value="3"/> Three</label>
<div>currently selected: {{radioValue}}</div>
<button type="submit">Submit</button>
</form>
</body>
JS:
$scope.submitForm = function () {
console.log('Submitting');
console.log($scope.radioValue);
};
它记录“提交”,然后记录“
undefined
”。 最佳答案
当我使用点“。”时,它可以工作。符号。不知道为什么。
的HTML
<body ng-controller="ExamCtrl">
<form name="myForm">
<label><input type="radio" name="test" ng-model="radio.value" value="1"/> One</label>
<label><input type="radio" name="test" ng-model="radio.value" value="2"/> Two</label>
<label><input type="radio" name="test" ng-model="radio.alue" value="3"/> Three</label>
<div>currently selected: {{radioValue}}</div>
<button ng-click="submitAnswer(radio.value)">Submit</button>
</form>
</body>
JS
$scope.submitAnswer = function (selected) {
// $scope.answer = 'A';
console.log('submitting');
console.log(selected);
};