我一直在试图解决这个问题,但没有成功。我明白,getCurrentPosition()返回一个承诺,并在.then()函数中调用$ scope.map.center将工作。我也明白,$ scope在摘要循环中运行,并且它的属性和对象在promise解决时更新。我对这一切都很陌生,我希望自己有道理。
这就是说,我完全喜欢了解发生了什么,因为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
感谢您的详细解答!原谅我,如果我错过了你的解释,但我想知道为什么$ scope.map首先工作。 – nubianrover
它不是真的没有,你只是得到你在控制器功能顶部创建的对象,或者可能部分完成了调用。 –
在做了一些更多的检查之后,我现在认为它与HTML5地理位置返回称为坐标的特殊对象类型有关。这会满足我现在的好奇心。但是,那么我可能是错的。 – nubianrover