Angular UI Bootstrap通过对象属性提前输入

时间:2018-09-23 16:12:06

标签: angularjs angular angular-ui-bootstrap

我有一个类似的对象(模仿Map):

$scope.vehicles = {
   1:{id:1, model:'Sedan'},
   2:{id:2, model:'SUV'},
   3:{id:3, model:'Van'}
}

我需要使用ui引导程序提前输入的属性值(并通过'model'属性保存过滤)

下一个变体无法正常工作

<input type="text" ng-model="vehicle"
   uib-typeahead="vehicle as vehicle.model for (id, vehicle) in vehicles | filter:{model:$viewValue} | limitTo:10">

1 个答案:

答案 0 :(得分:0)

使用对象属性列表需要特殊功能

$scope.getVehicleList = function () {
   return Object.values($scope.vehicles);
}

提前输入元素:

<input type="text" ng-model="vehicle"
       uib-typeahead="vehicle as vehicle.model for vehicle in getVehicleList() | filter:{model:$viewValue} | limitTo:10">