【发布时间】:2016-05-31 22:40:35
【问题描述】:
我一直在尝试解决这个问题,但没有成功。我知道 getCurrentPosition() 返回一个承诺并在 .then() 函数中调用 $scope.map.center 将起作用。我也明白 $scope 在摘要循环中运行,并且它的属性和对象在承诺解决时更新。我对这一切都很陌生,我希望我是有道理的。
也就是说,我很想了解发生了什么,因为 console.log($scope.map) 按预期工作,{{ map.center }} 按预期显示,但 console.log(map.center) 返回.then() 函数之外的空对象。
提前感谢您的帮助!
$scope.map = {
control: {},
center: {},
zoom: 16
};
$geolocation.getCurrentPosition({
timeout: 60000,
maximumAge: 250,
enableHighAccuracy: true
}).then(function(position) {
$scope.map.center.latitude = position.coords.latitude;
$scope.map.center.longitude = position.coords.longitude;
});
//Output
console.log($scope.map); //returns full object including data within $scope.map.center
console.log($scope.map.center); //returns an empty object. I am looking to convert this to an array using lodash.
{{ map.center }} works fine and returns the coordinates of my current location
**编辑(上传的控制台图像)**
This is what I see in the console. First object is $scope.map Second object is $scope.map.center
【问题讨论】: