Reputation: 1028
I am using the latest version of material.angular and i have the following directive (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>
The following code in the controller (ignore the text, i am always responding the same data for testing):
vm.querySearch = querySearch;
vm.searchText = "";
// ******************************
// Internal methods
// ******************************
function querySearch(text){
DataService.getOpileakSearches().then(function(response){
console.log(response.searches);
return response.searches;
});
}
And i get the right data in 'response.searches', my console is displaying:
[
{
"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
}
]
But md-autocomplete dont show anything and no error.
Upvotes: 0
Views: 115
Reputation: 108
Update your method in controller like this
$scope.querySearch = function(text){
return DataService.getOpileakSearches().then(function(response){
console.log(response.searches);
return response.searches;
});
}
Upvotes: 1