Angular Material: 设置单选按钮组的默认选项

Angular Material: Setting default option from radio button group

我一直在玩 Angular Material。我认为它很棒,但我不知道如何为单选按钮列表设置默认值。我尝试设置值和文本以及 Selected 但没有成功。

$scope.rdButton.value = 'Yes';
$scope.rdButton.text = 'Yes';

其中 rdButtonng-model 组的名称。关于如何实现这一目标的任何想法?

谢谢

如果 rdButtonng-model,只需设置 $scope.rdButton = 'Yes'; 即可将值为 Yes 的收音机设置为默认值。

只需提及您想select默认

哪个元素的ng-model

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>

供参考https://plnkr.co/edit/8XRnXb49cbXZpHhxBLW2?p=preview

假设你在 HTML 中有这样的东西:

<input type="radio" ng-model="rdButton" value="Yes">
Yes
</input>
<input type="radio" ng-model="rdButton" value="No">
No
</input>

您只需在控制器中执行此操作即可:

$scope.rdButton= 'Yes';