如何填充角UI引导键盘缓冲带最新$资源 [英] How to populate Angular UI Bootstrap Typeahead with newest $resource
问题描述
根据这个的帕维尔·科兹洛夫斯基的回答,键盘缓冲来自AngularUI-引导时,应该获得异步在$资源弹出项目工作最新版本的角度(我使用1.2.X)。
According to this Paweł Kozłowski's answer, Typeahead from AngularUI-Bootstrap should work when asynchronously obtaining popup items with $resource in newest Angular versions (I'm using 1.2.X).
我想我不知道如何使用它正确(结果我得到了 typeaheadHighlight
指令的code错误 - 预输入款待立即返回资源
能够像字符串和轮胎强调他们)。
I guess I don't know how to use it properly (As a result I get an error in typeaheadHighlight
directive's code - typeahead treats instantly returned Resource
s as strings and tires to highlight them).
我觉得关键code是:
I think the critical code is:
$scope.cities = function(prefix) {
var p = dataProviderService.lookup({q: prefix}).$promise;
return p.then(function(response){
$log.info('Got it!');
return response.data;
});
return p;
};
我试过的东西一大堆 - 返回 $承诺
(从Plunker版),查询()
, 则()
。结果
目前,我使用 $ HTTP
在我的应用程序这个功能,我确定它。不过,只是想知道如何达到同样以 $资源
。
I've tried bunch of stuff - returning $promise
(version from Plunker), query()
, then()
.
Currently, I'm using $http
for this functionality in my app and I'm ok with it. Still, just wanted to know how to achieve the same with $resource
.
您可能想看看这个:的https://github.com/angular/angular.js/commit/05772e15fbecfdc63d4977e2e8839d8b95d6a92d
为 ui.bootstrap.typeahead
在$资源的承诺API这些变化是否兼容?
You might want to take a look at this: https://github.com/angular/angular.js/commit/05772e15fbecfdc63d4977e2e8839d8b95d6a92d
is ui.bootstrap.typeahead
compatible with those changes in $resource's promise API ?
推荐答案
应该是:
$scope.cities = function(prefix) {
return dataProviderService.lookup({q: prefix}).$promise.then(
function(response){
// might want to store them somewhere to process after selection..
// $scope.cities = response.data;
return response.data;
});
};
这是基于角度提交上述的,它为我工作的角度1.2.13
This is based of the angular commit mentioned above, and it worked for me on Angular 1.2.13
这篇关于如何填充角UI引导键盘缓冲带最新$资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!