Hello I have a md auto complete search box, my issue is that when typing a name the search function is called. The search function calls onto an api but in the meantime it returns a null array to the auto complete form. Is there a way to tell the function to not return anything and go back with an answer after it found something? Also, making the md auto complete display a loading text or image while we wait for these results? Please find the code below:
CODE: html -
<md-autocomplete md-selected-item="selectedLocation" md-selected-item-change="selectLocation(item)" md-search-text="searchText"
md-items="item in searchLocations(searchText)" md-item-text="item.Name" md-min-length="3" placeholder="search location" md-select-on-match="true"
md-match-case-insensitive="true" md-no-cache="true">
<md-item-template>
<span md-highlight-text="searchText">{{item.id}}</span>
</md-item-template>
<md-not-found>
No results found.
</md-not-found>
</md-autocomplete>
JS-
$scope.searchLocations = function(txt) {
console.log("Searching locations in " + txt);
if (!isNaN(txt) && txt.length == 6) {
params = {locationIds: [txt]};
}
locations = Location.query(params);
console.log("locations found:" + locations.length); //this return 0 every time
return locations;
}
I finally figured this issue. Just in case anybody runs into this, you can do a promise and make sure you return the promise! in my case i did: