Angucomplete-alt: Remote-API-handler not working as expected

别来无恙 提交于 2020-01-02 07:36:34

问题


I'm using angucomplete-alt (https://github.com/ghiden/angucomplete-alt) in an AngularJS project, however I can't seem to make it work.

I'm trying to build a really simple autocomplete form, like this:

<angucomplete-alt pause="400" selected-object="obj" remote-api-handler="search" title-field="id" minlength="1" />

And my function is defined in the controller as such:

    $scope.search= function (userInputString, timeoutPromise) {
    return $timeout(function () {
        return [{ "id": "1" }, { "id": "2" }, { "id": "3" }]
    }, 1000);

However, everytime I try to search, I get "No results", even though the console logs no errors and the function is being called fine. What am I doing wrong?


回答1:


Ok, I've found a solution. Even though it's not specified at all in the docs, the directive expects a response like:

{"data": [Array of objects]}

Therefore, it works if I do it like:

$scope.search= function (userInputString, timeoutPromise) {
return $timeout(function () {
    return {"data": [{ "id": "1" }, { "id": "2" }, { "id": "3" }]};
}, 1000);

Hope it will help others.



来源:https://stackoverflow.com/questions/32251694/angucomplete-alt-remote-api-handler-not-working-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!