如何在typeahead angular中显示2个属性?

时间:2015-08-31 23:32:18

标签: angularjs angular-ui-typeahead

我正在使用角度bootstrap typeahead:

<input type="text" ng-model="selected" selectState(state.id) typeahead-on-select='onSelect($item, $model, $label)'  typeahead="state.name for state in states | filter:$viewValue | limitTo:8" class="form-control">

目前我正在显示state.name属性。有没有一种在输入中一起显示state.id和state.name的快捷方法?

plunkr: http://plnkr.co/edit/PVXPUiUmLyi80XkY5F9V?p=preview

1 个答案:

答案 0 :(得分:1)

是的,有:

<input type="text" ng-model="selected" selectState(state.id) typeahead-on-select='onSelect($item, $model, $label)'  typeahead="(state.id + ' ' + state.name) for state in states | filter:$viewValue | limitTo:8" class="form-control">

state.name更改为(state.id + ' ' + state.name)