从控制器以编程方式打开md-select

时间:2016-12-06 03:43:53

标签: angularjs angular-material

我有一个场景,我需要根据页面加载的某些条件打开md-select框。我检查了doumentation here,但API中没有提到这样的选项。

赞赏实现此目的的任何输入/链接。

感谢您的帮助。

1 个答案:

答案 0 :(得分: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>
相关问题