我使用的AngularJS与传单指示。
为了将标记传递给指令,我使用了一个服务,这很好。
如我所料,标记存储在$scope.markers中。
但是,当我拖动一个标记$scope.markers的值没有更新时,我添加了一个监视监听器来检查,如下所示:
$scope.$watch("markers", function(newValue, oldValue) {
$log.info($scope.markers.m1);
});当我从主控制器更新标记时,我看到它们正在更新。在拖动时,他们没有,所以我改变了指令,包括markerData与广播事件在拖尾,但我被告知,我需要改变角传单指令,以获得理想的结果。
在MapController和创建标记的控制器中,我添加了:
$scope.$on('leafletDirectiveMarker.dragend',function (e,marker) {
var markerName=marker.markerName
$scope.markers[markerName]=marker.markerData
});这件事现在很好,但我忍不住认为我做错了。
发布于 2013-09-19 15:28:19
如何将markers数组添加到您的作用域?根据示例页面,需要通过调用angular.extend($scope, {...});来扩展范围
http://tombatossals.github.io/angular-leaflet-directive/#!/examples/dragging-markers (在javascript角控制器选项卡中)
https://stackoverflow.com/questions/18898175
复制相似问题