我正在使用 md-autocomplete 元素,但是当搜索字段为空时没有下拉菜单。它甚至不调用 querySearch 函数。当我输入任何内容时,都会触发该功能并且自动完成功能会起作用。我究竟做错了什么?
的HTML:
<md-autocomplete
md-selected-item="selectedItem"
md-no-cache="true"
md-search-text="searchText"
md-items="item in querySearch(searchText)"
md-item-text="item.name"
placeholder="Select a Product">
<span md-highlight-text="searchText">
{{ '{{item.originalName}} ({{item.id}})' }}
</span>
</md-autocomplete>
JavaScript:
function querySearch(query) {
var results = query ? $scope.products.filter(createFilterFor(query)) : $scope.products;
return results;
}
function createFilterFor(query) {
var lowercaseQuery = angular.lowercase(query);
return function filterFn(item) {
return (angular.lowercase(item.originalName).indexOf(lowercaseQuery) === 0);
};
}