我一直在玩Angular Material。我认为它很棒,但我无法弄清楚如何为单选按钮列表设置默认值。我试图设置值和文本以及选择没有运气。Angular Material:设置单选按钮组的默认选项
$scope.rdButton.value = 'Yes';
$scope.rdButton.text = 'Yes';
rdButton
随着作为ng-model
组的名称。有关如何完成此任何想法?
感谢
我一直在玩Angular Material。我认为它很棒,但我无法弄清楚如何为单选按钮列表设置默认值。我试图设置值和文本以及选择没有运气。Angular Material:设置单选按钮组的默认选项
$scope.rdButton.value = 'Yes';
$scope.rdButton.text = 'Yes';
rdButton
随着作为ng-model
组的名称。有关如何完成此任何想法?
感谢
如果rdButton
是ng-model
,刚刚成立$scope.rdButton = 'Yes';
设置有值Yes
作为默认收音机。
刚刚提到NG-模型,其中elemntü要选择默认
JS
$scope.price_options = [{
price: 10
}, {
price: 7
}];
$scope.selected_price_option = $scope.price_options[1];
HTML
<div ng-repeat="price_option in price_options">
<label>
<input type="radio" ng-model="$parent.selected_price_option" ng-value="price_option" name="quantity" />{{price_option.price}}</label>
</div>
{{selected_price_option}}
</div>
假设你有这样的事情在HTML:
<input type="radio" ng-model="rdButton" value="Yes">
Yes
</input>
<input type="radio" ng-model="rdButton" value="No">
No
</input>
你只需要做到这一点的控制器:
$scope.rdButton= 'Yes';
工作很好。谢谢。 –
它总是让我很烦当这些超级简单的人得到我的好。这工作像一个魅力。感谢TJ和akazemis的帮助。我很感激。 –