Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit 348726d

Browse files
committed
Add custom function support for remote data
1 parent 2f53f08 commit 348726d

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ var app = angular.module('app', ["angucomplete-alt"]);
9494
| pause | The time to wait (in milliseconds) before searching when the user enters new characters. [example](http://ghiden.github.io/angucomplete-alt/#example1) | No | 400 |
9595
| selected-object | Either an object in your scope or callback function. If you set an object, it will be two-way-bound data as usual. If you set a callback, it gets called when selection is made. [example](http://ghiden.github.io/angucomplete-alt/#example1) | Yes | selectedObject or objectSelectedCallback |
9696
| remote-url | The remote URL to hit to query for results in JSON. angucomplete will automatically append the search string on the end of this, so it must be a GET request. [example](http://ghiden.github.io/angucomplete-alt/#example5) | No | http://myserver.com/api/users/find?searchstr= |
97+
| get-remote-data-function | A function in the controller that would receive the string and some parameters like the timeout promise, and would return a promise with the request for the data | No | - |
9798
| remote-url-data-field | The name of the field in the JSON object returned back that holds the Array of objects to be used for the autocomplete list. [example](http://ghiden.github.io/angucomplete-alt/#example5) | No | results |
9899
| title-field | The name of the field in the JSON objects returned back that should be used for displaying the title in the autocomplete list. Note, if you want to combine fields together, you can comma separate them here (e.g. for a first and last name combined). If you want to access nested field, use dot to connect attributes (e.g. name.first). [example](http://ghiden.github.io/angucomplete-alt/#example1) | Yes | firstName,lastName |
99100
| description-field | The name of the field in the JSON objects returned back that should be used for displaying the description in the autocomplete list. [example](http://ghiden.github.io/angucomplete-alt/#example6) | No | twitterUsername |

angucomplete-alt.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
remoteUrlRequestWithCredentials: '@',
7979
remoteUrlResponseFormatter: '=',
8080
remoteUrlErrorCallback: '=',
81+
getRemoteDataFunction: '=',
8182
id: '@',
8283
type: '@',
8384
placeholder: '@',
@@ -441,6 +442,17 @@
441442
.error(httpErrorCallback);
442443
}
443444

445+
function getResourceResults(str) {
446+
cancelHttpRequest();
447+
448+
httpCanceller = $q.defer();
449+
var params = { timeout: httpCanceller.promise };
450+
451+
scope.getRemoteDataFunction(str, params).$promise
452+
.then(httpSuccessCallbackGen(str))
453+
.catch(httpErrorCallback);
454+
}
455+
444456
function clearResults() {
445457
scope.showDropdown = false;
446458
scope.results = [];
@@ -496,7 +508,9 @@
496508
getLocalResults(str);
497509
});
498510
}
499-
else {
511+
else if (scope.getRemoteDataFunction) {
512+
getResourceResults(str);
513+
} else {
500514
getRemoteResults(str);
501515
}
502516
}

0 commit comments

Comments
 (0)