在我的html页面中定义控制器和ng-app之后,我使用了angularjs typehead来实现自动完成功能。
HTML
<input type="text" ng-model="selected" uib-typeahead="location for location getLocation($viewValue)" typeahead-loading="loadingLocations" typeahead-no-results="noResults" class="form-control" placeholder="json data">
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
<div ng-show="noResults">
<i class="glyphicon glyphicon-remove"></i> No Results Found
</div>
的JavaScript
$scope.getLocation = val => {
return $http.get('./resultlocation.json', {
params: {
address: val
}
}).then(response => {
return response(item => item.name);
});
};