我正在尝试使用新的地理代码值更新字段,但即使模型已更新,它也不会与第一次调用绑定(bind)。我的 Controller 代码如下:
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().$apply();
参见http://fiddle.jshell.net/yfLek2cw/
此外,你原来的 fiddle 中的 Angular CDNLink 也不起作用。原因是,地理位置回调不是从 Angular 完成的。因此脏检查机制在那里不起作用。要再次启动脏检查,您必须调用 $scope.$apply();
这是所有外部回调函数所必需的,即使这些回调位于 Angular 范围内。 Auto $apply 仅适用于 $timeout 或 $q 服务等 Angular 回调
关于javascript - ng-model 数据 bing 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25429225/