180
rated 0 times
[
187]
[
7]
/ answers: 1 / hits: 15610
/ 9 Years ago, sun, november 22, 2015, 12:00:00
What i'm trying to do is an Angular Material autocomplete (md-autocomplete) with data dynamically retrieved from an AJAX call to my REST API. Unfortunately I get only indeterminate progress bar instead of autocomplete items as you can see below.
Result
Controller
$scope.customersSelect = {};
$scope.selectedItem = null;
$scope.searchText = null;
$scope.getCustomers = function (query) {
selectsService.getCustomers(query).then(function (results) {
$scope.customersSelect = results.data;
console.log($scope.customersSelect);
}, function(error) {
alert(error.data.message);
});
}
Service
var selectsServiceFactory = {};
_getCustomers = function (query) {
return $http.get(serviceBase + 'api/selects/customers/' + query)
.then(function(results) {
return results;
});
}
selectsServiceFactory.getCustomers = _getCustomers;
return selectsServiceFactory;
View
<md-autocomplete md-floating-label=Klient
autocomplete=off
flex=
md-search-text-change=getCustomers(searchText)
md-item-text=item
md-items=item in customersSelect
md-search-text=searchText
md-selected-item=machine.customerId
md-input-maxlength=100
md-input-minlength=2
md-input-name=machineOwner>
<md-item-template>
<span md-highlight-text=searchText>{{item}}</span>
</md-item-template>
I'm getting the data successfully from the API, because I can see it printed in the console.
More From » angularjs