我正在嘗試製作一個角度指令,該指令需要帶有問題和若干答案的對象。然後,它應該將答案顯示爲單選按鈕,以便用戶可以選擇一個投票,然後將其發送回服務器。角度指令中的單選按鈕不起作用
在我的版本上,ng-model/scope變量沒有更新。
<div>
<h3> {{poll.question}}</h3>
<div class="list-group">
<form>
<label ng-repeat="option in poll.options" for="{{option.optionName}}">{{option.optionName}}
<input type="radio" id="{{option.optionName}}" ng-model="selectedOption" ng-value="option.optionName" name="option"/>
</label>
</form>
</div>
<button ng-class="btn" ng-click="sendOption()">Send Vote</button>
<p>the option you selected is: {{selectedOption}}</p>
.directive('voter', function() {
return {
templateUrl: 'app/voter/voter.html',
restrict: 'EA',
scope:{
poll:'='
},
controller:function($scope,$http,Auth){
$scope.selectedOption = 'no option selected';
$scope.sendOption = function(){console.log($scope.selectedOption);};
},
link: function (scope, element, attrs) {
}
};
})
它顯示的選項投票答案,但$ scope.selectedOption不會改變?我之前沒有在Angular上使用單選按鈕,所以可能錯過了一些明顯的東西。
感謝任何幫助