1
我該如何角色化這個js函數?我需要它異步使用。我的理解是,然後角度可以做到這一點。將js回調函數轉換爲帶有promise的angular。然後
function showResult(result) {
var lat = result.geometry.location.lat();
var long = result.geometry.location.lng();
$scope.vm.showroom.Longitude = long;
$scope.vm.showroom.Latitude = lat;
}
function GetLatitudeLongitude(callback, address) {
var address1 = address || '234 eisenhower avenue salt lake city';
// Initialize the Geocoder
var geocoder = new google.maps.Geocoder();
if (geocoder) {
geocoder.geocode({
'address': address1
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
callback(results[0]);
}
});
}
}
查覈在角 HTTPS的'$ q'服務: //docs.angularjs.org/api/ng/service/$q – LoganRx