角度材质:从单选按钮组设置默认选项

时间:2016-06-28 06:39:16

标签: angularjs radio-button angular-material

我一直在玩Angular Material。我认为它很棒,但我无法弄清楚如何为单选按钮列表设置默认值。我试图设置值和文本以及选择没有运气。

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

rdButton组成为ng-model组的名称。有关如何实现这一点的任何想法?

由于

3 个答案:

答案 0 :(得分:0)

如果rdButtonng-model,则只需将$scope.rdButton = 'Yes';设置为将值为Yes的广播设置为默认值。

答案 1 :(得分:0)

只提一下你想要选择默认值的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

答案 2 :(得分:0)

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

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

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

$scope.rdButton= 'Yes';
相关问题