md-autocomplete (HEAD:master) не отображает HTTP-ответ
Я использую последнюю версию https://material.angularjs.org/HEAD/ и у меня есть следующая директива (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 ничего не показывает и без ошибок.
1 ответ
Решение
Обновите свой метод в контроллере, как это
$scope.querySearch = function(text){
return DataService.getOpileakSearches().then(function(response){
console.log(response.searches);
return response.searches;
});
}