I've been struggling with this issue for a while. I am working with ion-autocomplete and trying to retrieve data using a factory.
The Factory I'm using is as follows:
myApp.factory('items', function($http){
return {
list: function(query,callback){
$http.get('http://192.168.100.100/myApp/products/' + query).success(callback)
}
};
});
To fetch the data, I use:
items.list(function(items) {
$scope.items = items;
});
In the autocomplete demo, the request data looks like this:
$scope.getTestItems = function (query) {
return {
items: [
{id: "1", name: query + "1", view: "view: " + query + "1"},
{id: "2", name: query + "2", view: "view: " + query + "2"},
{id: "3", name: query + "3", view: "view: " + query + "3"}]
};
};
I thought this solution would work:
$scope.getTestItems = items.list(query,function(items)
{
console.log(items);
return items;
}
)
However, it's clear that it's not working. I also tried:
$scope.getTestItems = function(query)
{
items.list(query,function(items)
{
console.log(items);
return items;
}
)
}
Although this does show me the result in the console, it's not being returned to getTestItems
.