【发布时间】:2015-11-26 06:12:23
【问题描述】:
我正在尝试在我的网站中使用 Angular Material 的自动完成组件。
在我的 html 代码中:
<md-autocomplete md-selected-item="selectedItem" md-search-text="searchText" md-items="item in getMatches(searchText)" md-item-text="item.display">
<md-item-template>
<span md-highlight-text="searchText">{{item.display}}</span>
</md-item-template>
<md-not-found>
No matches found.
</md-not-found>
</md-autocomplete>
在我的控制器中,我有以下内容:
app.controller('IndexController', function ($scope) {
$scope.getMatches = function (text) {
alert(text);
}
});
如您所见,我没有实施太多。但如果自动完成功能正在尝试查找某些内容,它应该执行 getMatches 并提醒文本。
在我的场景中,它除了打印“未找到匹配项”之外什么都不做。
没有文本输入可输入要搜索的文本。
我错过了什么?
jsfiddle https://jsfiddle.net/p7wc8psy/
【问题讨论】:
-
为 md-autocomplete 添加一个名称(用于生成的输入)。
-
我加了一个name属性,结果都一样
-
你能提供一个工作小提琴吗?
-
@iWörk 用 jsfiddle url 更新了主链接。谢谢
标签: angularjs angular-material md-autocomplete