我使用的是material.angular的最新版本,我有以下指令(md-autocomplete):
<md-autocomplete flex
md-no-cache="true"
md-selected-item="vm.selectedItem"
md-search-text="vm.searchText"
md-items="item in vm.querySearch(vm.searchText)"
md-item-text="item.id"
md-min-length="0"
md-floating-label="Búsqueda Opileak"
md-menu-class="autocomplete-custom-template">
<md-item-template>
<span class="item-title">
<md-icon class="fa fa-circle-o"></md-icon>
<span> {{item.id}} </span>
</span>
<span class="item-metadata">
<span class="item-metastat">
<strong>{{item.q}}</strong> q
</span>
<span class="item-metastat">
<strong>{{item.active}}</strong> active
</span>
</span>
</md-item-template>
</md-autocomplete>
控制器中的以下代码(忽略文本,我总是响应相同的数据进行测试):
vm.querySearch = querySearch;
vm.searchText = "";
// ******************************
// Internal methods
// ******************************
function querySearch(text){
DataService.getOpileakSearches().then(function(response){
console.log(response.searches);
return response.searches;
});
}
我在'response.searches'中获得了正确的数据,我的控制台显示:
[
{
"id": 10315,
"name": "13@@ayudaenaccion",
"q": "@ayudaenaccion",
"src": [
"TWITTER",
"TWITTER"
],
"src_type": null,
"start_interval": null,
"end_interval": null,
"location": null,
"geolocation": "",
"active": true
},
{
"id": 10316,
"name": "13@apadrinar",
"q": "apadrinar",
"src": [
"TWITTER",
"TWITTER"
],
"src_type": null,
"start_interval": null,
"end_interval": null,
"location": null,
"geolocation": "",
"active": false
},
{
"id": 10317,
"name": "13@ong",
"q": "ong",
"src": [
"TWITTER",
"TWITTER"
],
"src_type": null,
"start_interval": null,
"end_interval": null,
"location": null,
"geolocation": "",
"active": false
},
{
"id": 10327,
"name": "13@ayudaenaccion",
"q": "ayudaenaccion",
"src": [
"TWITTER",
"TWITTER"
],
"src_type": null,
"start_interval": null,
"end_interval": null,
"location": null,
"geolocation": "",
"active": true
}
]
但是md-autocomplete不会显示任何内容而且没有错误。
答案 0 :(得分:1)
在控制器中像这样更新你的方法
$scope.querySearch = function(text){
return DataService.getOpileakSearches().then(function(response){
console.log(response.searches);
return response.searches;
});
}