md-select显示已选择的值

时间:2017-01-03 14:38:46

标签: angularjs angular-material

所以我有以下内容:

<div layout-gt-sm="row">
    <md-input-container class="md-block" flex-gt-sm>
        <label>Documents</label>
        <md-select multiple ng-model="ctrl.data.documents" placeholder="Documents" ng-controller="DocumentsCtrl"> // I want to show the submitted values.
            <md-option ng-value="doc" ng-repeat="doc in allItems">{{ doc.name }}</md-option> // A list of other values
            <div ng-hide="allItems.length">No items found</div>
        </md-select>
    </md-input-container>
</div>

ctrl.data.documents是已选择值的数组。

我想要实现的是在字段选项中显示此数组(ctrl.data.documents)以及在这种情况下使用其他值ng-repeat的列表。 ng-repeat工作得很好。我可以选择其他值。但无法弄清楚如何显示已选择的值。

有些挖掘我认为ng-options可能会这样做,但似乎无法让它工作(不支持?)而且ng-selected也没有做到这一点。

任何帮助或想法?

更新#1:

添加了ctr.data.documents数组的图片。

map

1 个答案:

答案 0 :(得分:1)

您必须使用ng-model-options="{trackBy: '$value.id'}"ng-repeat="doc in allItems track by doc.id"id部分应该是您文档的识别标记。

<md-select multiple ng-model="ctrl.data.documents"
    ng-model-options="{trackBy: '$value.id'}"
    placeholder="Documents" ng-controller="DocumentsCtrl"> 
    <md-option ng-value="doc" ng-repeat="doc in allItems track by doc.id">{{ doc.name }}</md-option>
    <div ng-hide="allItems.length">No items found</div>
</md-select>

这里记录了大部分内容:https://material.angularjs.org/latest/api/directive/mdSelect