0
我有這些單選按鈕,但我無法從提交時獲得價值。我想這完全一樣的: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
。
你試過了你的plnkr嗎? –
你應該在控制器中初始化'$ scope.radioValue;'。 – ProCylon
@NiRmaL然後它只記錄初始化的值。 –