Below is my md-select dropdown. How do I preselect a list option from controller?
下面是我的md-select下拉列表。如何从控制器中预选列表选项?
<md-input-container ng-init="Vacancies()" class="md-block" style="margin:0 !important;">
<md-select ng-model="Vacancy" placeholder="Select a Vacancy" id="Md-select1" name="vacancy1" ng-change="setCriteria(Vacancy)">
<md-option ng-value="vac" ng-repeat="vac in vacancylist">{{vac.JobTitle}}</md-option>
</md-select>
{{vacancy.JobTitle}}
1 个解决方案
#1
0
I know at least 2 options to achieve that:
我知道至少有两个选项来实现这个目标:
Option 1
add to HTML: ng-selected="options.indexOf(option) == 1"
添加到HTML:ng-selected =“options.indexOf(option)== 1”
Something like:
就像是:
<md-select ng-model="selectedOption" md-on-open="mdSelectOnOpen()">
<md-option ng-repeat="option in options" ng-value="option"
ng-selected="options.indexOf(option) == 1"
>{{option.name}}</md-option>
</md-select>
Option 2
define md-select
ng-model
定义md-select ng-model
<md-select ng-model="selectedOption.id" md-on-open="mdSelectOnOpen()">
<md-option ng-repeat="option in options" ng-value="option.id"
>{{option.name}}</md-option>
</md-select>
where:
哪里:
$scope.options = [];
for(var i=1;i<=100;i++) {
$scope.options.push({id: i, name: "option " + i});
}
$scope.selectedOption = $scope.options[1];
演示Codepen
#1
0
I know at least 2 options to achieve that:
我知道至少有两个选项来实现这个目标:
Option 1
add to HTML: ng-selected="options.indexOf(option) == 1"
添加到HTML:ng-selected =“options.indexOf(option)== 1”
Something like:
就像是:
<md-select ng-model="selectedOption" md-on-open="mdSelectOnOpen()">
<md-option ng-repeat="option in options" ng-value="option"
ng-selected="options.indexOf(option) == 1"
>{{option.name}}</md-option>
</md-select>
Option 2
define md-select
ng-model
定义md-select ng-model
<md-select ng-model="selectedOption.id" md-on-open="mdSelectOnOpen()">
<md-option ng-repeat="option in options" ng-value="option.id"
>{{option.name}}</md-option>
</md-select>
where:
哪里:
$scope.options = [];
for(var i=1;i<=100;i++) {
$scope.options.push({id: i, name: "option " + i});
}
$scope.selectedOption = $scope.options[1];
演示Codepen