Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 507
LorDisturbia Avatar asked Aug 11 '26 01:08

LorDisturbia


1 Answers

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.

like image 197
LorDisturbia Avatar answered Aug 12 '26 15:08

LorDisturbia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!