gpt4 book ai didi

javascript - AngularJS Typeahead 回调函数

转载 作者:行者123 更新时间:2023-11-28 00:01:46 30 4
gpt4 key购买 nike

我知道这个回调函数有问题。但我不确定解决此问题的最佳方法是什么。

我有资源:

.factory("AutoCompleteResource", function ($http) {
return {
getAutoComplete: function (searchTerm) {
$http.get('/cdeCompletion/' + searchTerm, {}).then(function (response) {
response.data;
});
}
}
})

这是 Controller :

 $scope.getAutoComplete = function (searchTerm) {
AutoCompleteResource.getAutoComplete(searchTerm);
}

这是 html View :

<input name="searchTerms" id="searchTerms" type="text" class="form-control" ng-model="ftsearch"
ng-maxlength="500" placeholder="Search Common Data Elements"
typeahead-wait-ms="500" typeahead-min-length="3"
typeahead="searchQuery for searchQuery in getAutoComplete($viewValue) | filter:$viewValue | limitTo:8"
typeahead-focus-first="false" typeahead-on-select="gotoSearch()">

修复这里错误的最佳方法是什么?谢谢!

最佳答案

您需要将 promise 返回到预输入,因为它可以处理 promise 并自动解析数据,即

.factory("AutoCompleteResource", function ($http) {
return {
getAutoComplete: function (searchTerm) {
//Return here
return $http.get('/cdeCompletion/' + searchTerm, {}).then(function (response) {
return response.data; //return here
});
}
}
});

$scope.getAutoComplete = function (searchTerm) {
//Return here
return AutoCompleteResource.getAutoComplete(searchTerm);
}

关于javascript - AngularJS Typeahead 回调函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31731528/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com