问题
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