I\'m using Angular Material md-autocomplete
in my project. In that I\'m getting the suggest listing from the Service Host via ajax call using $http
Why not just put return countryList inside the success function.
function LoadAutocomplete(id) {
var countryList = [];
$http({
method: "post",
url: "https://www.bbminfo.com/sample.php",
params: {
token: id
}
})
.success(function (response) {
countryList = response.records;
return countryList;
})
.error(function (response) {
countryList = [];
return countryList;
});
}
edit due to deprecation of .success and .error methods:
function LoadAutocomplete(id) {
var countryList = [];
$http({
method: "post",
url: "https://www.bbminfo.com/sample.php",
params: {
token: id
}
})
.then(function (response) {
countryList = response.data.records;
return countryList;
},function () {
countryList = [];
return countryList;
});
}