我有这些单选按钮,但我无法从提交的单选按钮中获取值(value)。我尝试了完全相同的操作: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);
};
它记录“正在提交”,然后未定义
。
最佳答案
当我使用点“.”时它起作用符号。不知道为什么。
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);
};
关于javascript - 无法获取 Angular 单选按钮的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42039424/