Step 16 of angular-meteor tutorial
$scope.map = {
center: {
latitude: 45,
longitude: -73
},
zoom: 8,
events: {
click: function (mapModel, eventName, originalEventArgs) {
if (!$scope.party)
return;
if (!$scope.party.location)
$scope.party.location = {};
$scope.party.location.latitude = originalEventArgs[0].latLng.lat();
$scope.party.location.longitude = originalEventArgs[0].latLng.lng();
//scope apply required because this event handler is outside of the angular domain
$scope.$apply();
}
},
marker: {
options: { draggable: true },
events: {
dragend: function (marker, eventName, args) {
if (!$scope.party.location)
$scope.party.location = {};
$scope.party.location.latitude = marker.getPosition().lat();
$scope.party.location.longitude = marker.getPosition().lng();
}
}
}
};
为什么我们不需要在marker.events.dragend函数结束时调用$scope.$apply();
,但是我们需要在events.click函数结束时调用$scope.$apply();
?
请注意,我知道我们需要在events.click函数结束时调用$scope.$apply();
,因为此回调由Google Map API调用。 Isn"标记..events.dragend还有一个将由Google Map API调用的回调函数吗?