How to populate Angular UI Bootstrap Typeahead with newest $resource

让人想犯罪 __ 提交于 2019-11-30 20:23:10

Should be:

$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;
    });
};

This is based of the angular commit mentioned above, and it worked for me on Angular 1.2.13

Thanks to the answer from @andrew-lank, I did mine with $resource as well. I didn't have a data attribute in my response though. I used the query method on $resource, which expects a responsetype of array so maybe that is why there is no data attribute. It is an array of Resource objects, each of which contains the data. So my code is slightly simpler, looks more like this:

$scope.cities = function(prefix) {
    return dataProviderService.query({q: prefix}).$promise.then(
      function(response){
        return response;
    });
};
Private Winger

I ran into this same problem and it had me banging my head against the wall. The problem is with the data service since it is returning an array of strings instead of wrapping them in a JSON object. $resource will not work with an array of strings.

For additional info, check out this answer: One dimensional array of strings being parsed to 2d by angular resource

typeahead="i.t_UserName for i in employeeInfo | filter:$viewValue | limitTo:4"
goes as an attribute of your html input

and in your controller (using employee resource)

$scope.employeeInfo = getEmployeeResourceSvc.getEmplInfo.query(function(response){ $scope.employeeInfo= response; });

In the ui-bootstrap 13.0 and angular 1.3, you can now do the following:

$scope.cities = function (q) {
    return $scope.resource.query({ q: prefix }).$promise
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!