2016-12-06 27 views
0

我有一個場景,我需要在頁面加載時根據特定條件打開md選擇框。我檢查了doumentation here,但在API中沒有提到這樣的選項。以編程方式從控制器打開md-select

任何輸入/鏈接,以達到此讚賞。

感謝您的幫助。

+0

ü可以使用'NG-if'指令來檢查條件在選擇框中 –

+0

伍,如果是好的顯示或隱藏的元素,但問題是關於使用打開選擇框編程哪個屬性? – user1242321

回答

0

在我幾周前寫的代碼(http://codepen.io/nadeemramsing/pen/EgdqLg)中,我使用了ng-init和ng-selected來設置頁面加載的默認值。

<md-select ng-model="vm.selectedCountry" ng-init="vm.selectedCountry = vm.selectedCountry?vm.selectedCountry : 'CH';"> 

       <md-option ng-value="'CH'" ng-selected="vm.selectedCountry == 'CH'?true:false">Switzerland</md-option> 

       <md-option ng-repeat="country in vm.countries" ng-value="country.code"> 
        {{country.name}} 
       </md-option> 
</md-select> 
+0

我期待爲用戶打開選擇框,而不是選擇加載時的選項。有什麼想法嗎? – user1242321