【发布时间】:2014-08-21 14:39:14
【问题描述】:
我正在尝试使用新的地理代码值更新字段,但即使模型已更新,它也不会与第一次调用绑定。我的控制器代码如下:
function TheReportCtrl($scope) {
$scope.code = [];
$scope.code.lat = "19.2555500";
$scope.getCode = function () {
var geocoder = new google.maps.Geocoder();
var address = "12323 Barker Cypress Rd, Cypress, Texas"
geocoder.geocode({
'address': address
}, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
$scope.code.lat = results[0].geometry.location.k;
} else {
console.log("Geocoding failed: " + status);
}
});
}
}
我的代码缺少什么?
【问题讨论】:
-
你需要在
$scope.code.lat = results[0].geometry.location.k;之后调用$scope.$apply();。 AngularJS 不知道你改变了范围。 -
感谢 Sergiu Paraschiv 不幸的是,您的回答已在评论中。 :)
标签: javascript angularjs angularjs-ng-model