如何在AngularJS材料选择选项组中自定义显示的文本?

时间:2017-07-08 07:41:44

标签: angularjs angularjs-material

我这里有一个片段

<span class="filter-lbl">Filter&nbsp;by:</span>
<md-input-container>
    <md-select md-container-class="filter-contribution-cont" ng-model="selected" ng-change="selectedChanged(); updateSelectedContribution();" multiple>
        <md-optgroup>
            <md-option ng-value="data.label" ng-click="dropdownClick(data)" ng-selected="data.selected" ng-repeat="data in dataSet | unique: 'label'">{{data.label}}</md-option>
        </md-optgroup>
    </md-select>
</md-input-container>

例如,我有一个函数用于构造我想要显示的文本getSelectedContributions(),如何替换AngularJS Material生成的内置显示文本?

我还是AngularJS的新手,所以如果可能,我需要一个简单的解决方案。谢谢!

1 个答案:

答案 0 :(得分:0)

找到答案。我只需要在md-selected-text="getSelectedContributions()"中添加md-select,就像这样

<span class="filter-lbl">Filter&nbsp;by:</span>
<md-input-container>
    <md-select md-selected-text="getSelectedContributions()" md-container-class="filter-contribution-cont" ng-model="selected" ng-change="selectedChanged(); updateSelectedContribution();" multiple>
        <md-optgroup>
            <md-option ng-value="data.label" ng-click="dropdownClick(data)" ng-selected="data.selected" ng-repeat="data in dataSet | unique: 'label'">{{data.label}}</md-option>
        </md-optgroup>
    </md-select>
</md-input-container>