md-autocomplete response after ajax call does not update dropdown list
Hi guys
This has already been mentioned here however the solution wasn't posted and that issue has been closed - sorry to post it again.
I have the same issue, each keypress initiates an ajax call, which updates the available items, however the dropdown display updates before the ajax call completes. What this means is the available items in the dropdown are always showing the result of the ajax call which was initiated by the previous keypress. e.g. enter 1234 and the available options are the result of searching for 123.
below is my markup and code. Any suggestions on how to get it working properly ?
<md-autocomplete md-no-cache="true" placeholder="Search for client"
md-selected-item="vm.client" md-search-text="vm.searchText" md-items="item in vm.clients"
md-search-text-change="vm.searchClients(vm.searchText)" md-item-text="item.name"
md-min-length="2" md-floating-label="Client">
<md-item-template>
<span md-highlight-text="vm.searchText" md-highlight-flags="^i">{{item.name}}</span>
</md-item-template>
</md-autocomplete>
this.searchClients = function(searchText) {
var deferred = _this.$qService.defer();
_this.dataService.searchClients(searchText).then(function(results) {
_this.clients = results.data;
deferred.resolve(results.data);
});
return deferred.promise;
};
And my data service method:
this.searchClients = function(searchText) {
var config = {
url: "/api/Clients?searchText=" + searchText,
method: "GET",
headers: {
'Content-Type': "application/json; charset=utf-8"
}
};
return _this.$http(config);
};
Please post this in the Angular Material Forum
Even I am facing same issue with md-autocomplete. Not sure where the exact problem is. Is this is something to do with $apply or $ digest? Could someone please point to the solution.