我尝试过使用UI bootstrap和ion-autocomplete - 它们最适合静态数据。但我无法使用$ http请求。数据正在返回,但是当我将结果绑定到范围对象时,它不会被填充。
以下代码段适用于Ui bootstrap
$scope.autocomplete = function(query){
searchAutocompleteService.autoComplete(query).
then(
function(result){
$scope.Categories = result.data;
},
function(error){
}
)
}
<input type="text" placeholder="Search" ng-model="searchText" ng-keydown="autocomplete(searchText)" uib-typeahead="state for state in Categories" typeahead-no-results="noResults">
以下代码段用于离子自动完成
$scope.callbackMethod = function (query, isInitializing) {
searchAutocompleteService.autoComplete(query).
then(
function(result){
return result.data;
},
function(error){
return result.error;
}
)
}
<input ion-autocomplete type="text" ng-model="searchText" readonly="readonly"
class="ion-autocomplete" autocomplete="off" items-method="callbackMethod(query)"
items-method-value-key="items" item-value-key="name"
item-view-value-key="names" max-selected-items="1" />