主HTML:如何更新標記或從地圖控件的控制器中添加新標記?
<div ng-controller="MapCtrl as vm">
<ui-gmap-google-map center="vm.map.center" zoom="vm.map.zoom">
<ui-gmap-map-control template="mapControl.tpl.html" controller="MapControlCtrl"></ui-gmap-map-control>
<ui-gmap-marker idKey="vm.marker1.id" coords="vm.marker1.coords"></ui-gmap-marker>
</ui-gmap-google-map>
</div>
MapCtrl:
angularApp.controller('MapCtrl', function() {
var vm = this;
vm.map = {
zoom: 11,
center: {
latitude: ...,
longitude: ...
}
};
vm.marker1 = {
id: 1,
coords: {
latitude: ...,
longitude: ...
}
};
});
mapControl.tpl.html:
<button ng-click="addMarker()">Add</button>
<button ng-click="updateMarker1()">Update Marker 1</button>
MapControlCtrl:
angularApp.controller('MapControlCtrl', function($scope) {
$scope.addMarker = function() {
// how to add a marker to the map from within this method?
};
$scope.updateMarker1 = function() {
// how to update marker1 from within this method?
};
)};
如何從輔助控制器推它? –
使用服務在控制器間共享數據 – charlietfl