我有一个预定义的模型,我正在使用md-select(selectedVegetables)。当它的模型已经具有键和值时,它似乎不适用于我的模型。Code Pen
检查:
$scope.vegetables =
[{"key":"1","value":"Banana"},{"key":"2","value":"Apple"}];
$scope.selectedVegetables = [{"key":"1","value":"Apple"}];
在我的控制器中。
和我的HTML
<md-input-container>
<label>Vegetables</label>
<md-select ng-model="selectedVegetables" md-on-close="clearSearchTerm()" data-md-container-class="selectdemoSelectHeader" multiple="">
<md-select-header class="demo-select-header">
<input ng-model="searchTerm" placeholder="Search for a vegetable.." class="demo-header-searchbox md-text" type="search">
</md-select-header>
<md-optgroup label="vegetables">
<md-option ng-value="vegetable" ng-repeat="vegetable in vegetables |
filter:searchTerm">{{vegetable}}</md-option>
</md-optgroup>
</md-select>
</md-input-container>
答案 0 :(得分:0)
我找到了解决方案。 解决方案是将其添加到md-select
ng-model-options="{trackBy: '$value.key'}"