Sunil Vurity Sunil Vurity - 4 months ago 56
AngularJS Question

AngularJS UISelect - call REST API on search ( Min 3 chars )

Im using Angular-UISelect to enable search for my dropdown.

Now i have a challenge.

  1. Need to create a controller level filter ( scoped to controller not app ) that takes 3 min characters from user and hit REST Api based on 3 chars and bind the result from API back to UISelect.


  1. Initial load of UIselect will not have any data.

  2. User types 3 chars

  3. Fire a filter(controller scoped) which calls REST API with 3 chars

  4. bind REST API response to UISelect.

when i looked at UISelect demo,it performs search on already bound data.

Need some inputs on how to go about it.


you need to use

<ui-select-choices repeat="address in addresses track by $index"

and in this function refreshAddresses you can put your logic

$scope.refreshAddresses = function(input) {
    if(angular.isUnDefined(input) || input == null) return [];
    if(input.length < 3) return [];
    return $http.get() //your logic