2016-06-28 137 views
0

我一直在玩Angular Material。我認爲它很棒,但我無法弄清楚如何爲單選按鈕列表設置默認值。我試圖設置值和文本以及選擇沒有運氣。Angular Material:設置單選按鈕組的默認選項

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

rdButton隨着作爲ng-model組的名稱。有關如何完成此任何想法?

感謝

回答

0

如果rdButtonng-model,剛剛成立$scope.rdButton = 'Yes';設置有值Yes作爲默認收音機。

+1

它總是讓我很煩當這些超級簡單的人得到我的好。這工作像一個魅力。感謝TJ和akazemis的幫助。我很感激。 –

0

剛剛提到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> 

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

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'; 
+0

工作很好。謝謝。 –