<h4>Asynchronous results</h4>
the <pre>Model: {{asyncSelected | json}}</pre>
<input type="text" ng-model="asyncSelected" placeholder="Locations loaded via $http" uib-typeahead="address for address in getLocation($viewValue)" typeahead-loading="loadingLocations" typeahead-no-results="noResults" class="form-control">
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
<div ng-show="noResults">
<i class="glyphicon glyphicon-remove"></i> No Results Found
</div>
// Any function returning a promise object can be used to load values asynchronously
$scope.getLocation = function(val) {
return $http.get('//maps.googleapis.com/maps/api/geocode/json', {
params: {
address: val,
sensor: false
}
}).then(function(response){
return response.data.results.map(function(item){
return item.formatted_address;
});
});
};
$scope.getTarifZones = function(val) {
var result = [];
var getLocations = function(value) {
return $http.get('/api/locations', {
params: {
address: 'Kazakhstan Almaty '+value
}
}).then(function(response){
var featureMember = response.data.response.GeoObjectCollection.featureMember;
featureMember.map(function(item){
return {
place item.GeoObject.name
type: 'Address'
};
});
var zones = _.filter($scope.order.client.places, function (place) {
return place.place.address.indexOf(val) >=0;
}).map(function (place) {
place.place.type = 'zones';
return place;
});
result = _.concat(zones, featureMember);
console.log('locations ', result);
});
};
getLocations(val);
return result;
};
$scope.getTarifZones = function(val) {
function getLocations(value) {
var result = [];
return $http.get('/api/locations', {
params: {
address: 'Kazakhstan Almaty '+value
}
}).then(function(response){
var featureMember = response.data.response.GeoObjectCollection.featureMember;
featureMember.map(function(item){
return {
place item.GeoObject.name
type: 'Address'
};
});
var zones = _.filter($scope.order.client.places, function (place) {
return place.place.address.indexOf(val) >=0;
}).map(function (place) {
place.place.type = 'zones';
return place;
});
result = _.concat(zones, featureMember);
return result;
});
};
return getLocations(val);
};
Find more questions by tags AngularNode.jsComputer networksYandex.MapsAJAX