【发布时间】:2018-06-04 17:37:10
【问题描述】:
我有以下 uib-typeahead 标记:
<input type="text" class="form-control" id="field_location" ng-model="surveyData.location"
placeholder="Search"
uib-typeahead="location as location.name for location in newListLocations | filter:$viewValue:customSearch | orderBy:location.country.name | limitTo:200"
typeahead-editable="false">
我使用在后端完美运行的 REST 调用对其进行更新,这是我在控制器中使用它的方式(取自 this question):
$scope.filterLocations = function(searchValue, viewValue) {
var newListOfLocations = LocationTypeaheadFilter.queryWithTypeaheadSearchValue(viewValue).then(function (list){
$scope.newListLocations = list.data;
console.log($scope.newListLocations);
return $scope.newListLocations;
},
function errorCallback(response) {
alert('Error');
throw response;
});
return newListOfLocations;
};
使用标记中的原始函数调用此函数:
$scope.customSearch = function(searchValue, viewValue){
return $scope.filterLocations(searchValue, viewValue);}
我一开始尝试将所有逻辑放在同一个方法中,但没有区别,预先输入的列表总是为空,即使当我在控制台上的.then 区域登录它时,它显示了我的所有值期待它坚持下去。
我尝试了许多不同的方法,但我相信它应该按照我编写的方式工作,前提是我正在等待回调
EDIT 添加我定义 Angular 服务的工厂:
.factory('LocationTypeaheadFilter', function ($http, DateUtils) {
return {
queryWithTypeaheadSearchValue: function(query){
return $http.get("api/locationssearchTypeahead/"+query)
}
}});
【问题讨论】:
标签: javascript angularjs asynchronous angular-ui-bootstrap