Reputation: 73
As stated Angular-Material md-autocomplete's documentation:
The md-autocomplete uses the the md-virtual-repeat directive for displaying the results inside of the dropdown.
I've faced with a problem that I can't find any snippet how can I use virtual repeat inside of autocomplete.
I understand that I have to use a specific structure for infinite scroll according to md-virtual-repeat's documentation.
I have md-autocomplete:
<md-autocomplete
md-no-cache="true"
md-selected-item="obj.selectedItem"
md-search-text="obj.searchText"
md-items="item in infiniteItems"
md-item-text="item.name"
md-on-demand>
<md-item-template>
<span md-highlight-text="obj.searchText" md-highlight-flags="i">{{item.name}}</span>
</md-item-template>
<md-not-found>
not found!
</md-not-found>
</md-autocomplete>
And I have infiniteItems object, according to md-virtual-repeat suggestions:
$scope.infiniteItems = {
numLoaded_: 0,
toLoad_: 0,
items: [],
getItemAtIndex: function(index) {
if (index > this.numLoaded_) {
this.fetchMoreItems_(index);
return null;
}
return this.items[index];
},
getLength: function() {
return this.numLoaded_ + 5;
},
fetchMoreItems_: function(index) {
if (this.toLoad_ < index) {
this.toLoad_ += 20;
restService.getData().then(angular.bind(this, function(response) {
this.items = this.items.concat(response.data);
this.numLoaded_ = this.toLoad_;
}));
}
}
}
As result rest load data first time after loading entire page, and when I try to type smth I get mesage "not found" and dropdown with loaded data even do not open.
So, what am I doing wrong?
Thanks in advance!
Upvotes: 4
Views: 752
Reputation: 26075
There is a problem in your md-autocomplete
tag attribute, change
md-items="item in infiniteItems"
to
md-items="item in infiniteItems.items"
and you should be able to see auto complete list.
Upvotes: 0