Search code examples
angularjsautocompleteng-tags-input

ng-tags-input not working as desired


I am using ng-Input-tags in my angular project.But when I am searching the keyword my autocomplete is not getting updated with the searched results. I checked my method it is returning correct results but they are not appearing in dropdown of autocomplete.

This is my html code:

<tags-input ng-model="selectedDrivers" display-property="name" replace-spaces-with-dashes="false" add-from-autocomplete-only="true" placeholder="Search by driver name or driver id.." on-tag-added="emptyScope()"> <auto-complete source="searchDriver($query)" debounce-delay="500"></auto-complete> </tags-input>

And this is my js code:

$scope.searchDriver = function(query) { $scope.searchedResults = []; for(var key in $scope.driversInfo){ if($scope.driversInfo[key].name.toLowerCase().indexOf(query.toLowerCase()) >= 0 || $scope.driversInfo[key].id.toString().indexOf(query.toString()) >= 0) $scope.searchedResults.push($scope.driversInfo[key]); } return $scope.searchedResults; };

Somehow the suggestionList is not getting updated.


Solution

  • The source attirbute of the autocomplete is waiting for a promise so you have to use $q.

      let result: Array<any> = list.filter(
      (elt: any) => { return elt[property].toLowerCase().indexOf(query.toLowerCase()) !== -1; });
      deferred.resolve(result);
      return deferred.promise;