gpt4 book ai didi

javascript - angular-bootstrap typeahead 使用 $http

转载 作者:行者123 更新时间:2023-11-30 12:16:20 25 4
gpt4 key购买 nike

我尝试将 angular-bootstrap 的 typeahead 插件与 $http 服务一起使用。首先,我像这样使用 $http.success() :

$scope.filterProvinces = function(val){
return service.provinceList({
pageSize : 10,
queryKey : val
}).success(function(data, status, headers, config){
return data.data.list;
}
).error(function(data, status, headers, config){
alert("no result!");
return ;
});
}

但它没有用,所以我更改了代码,如下所示:

$scope.filterProvinces = function(val){
return service.provinceList({
pageSize : 10,
queryKey : val
}).then(function(response){
return response.data.data.list;
});
}

它正在运行,所以我很困惑。为什么 then() 可以,但 success() 不对。

最佳答案

如果您检查 AngularJS source ,你会发现.success()其实是把一个函数本身作为参数,然后调用这个函数,传入解构的response对象,最终调用.then() 解决 promise 。

由于不清楚,这实际上已被弃用,$http 的文档建议使用 .then() 代替。

The $http legacy promise methods success and error have been deprecated. Use the standard then method instead. If $httpProvider.useLegacyPromiseExtensions is set to false then these methods will throw $http/legacy error.

值得检查以确保没有抛出此错误。

关于javascript - angular-bootstrap typeahead 使用 $http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32343677/

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