While working for an autocomplete funtionality in angularJS encountered a problem where instead of the JSON we need to iterate each element and have to make an Array of string.
For iterating the JSON data(from server side), we used:
$scope.complete = function(){
WebService.getData($scope.search)
.then(function(response){
$scope.data = response.data.dataList;
//we can use function(item) instead of function(item, index) if index number is not required
angular.forEach($scope.data, function(item, index){
$scope.values[index] = item.data1+","+item.data2;
})
$("#suggestion").autocomplete({ source: $scope.values });
},function(error){
console.log('error');
});
}
Here scope.values is array of string, where we have put all the data.
0 Comment(s)