【发布时间】:2013-08-22 14:57:06
【问题描述】:
我正在使用http://nlaplante.github.io/angular-google-maps/ 在我的 Angular 应用程序中显示地图。 我的页面有一个通用控制器来获取 Json。 为了显示标记,我在范围内使用 $watch,因为我会实时进行,并且标记位置可以改变。
$scope.model = new Model 'api/now.json'
$scope.state = new DState
$scope.$watch ->
markers = []
_($scope.model.objects).each (obj) ->
markers.push
latitude: obj.latitude
longitude: obj.longitude
infoWindow: "<info-window>SHOULD NOT DISPLAY CAUSE DIRECTIVE</info-window>"
markers
, (newValue) ->
$scope.state.map.markers = newValue
, true
我的指令是基本的:
am.directive "infoWindow", ->
restrict: 'E'
template: "<div>IN DIRECTIVE</div>"
replace: true
我的 Html 页面调用地图:
#dashboard{ng:{controller: 'dashboardCtrl'}}
#map.google-map{center: 'state.map.center',
zoom: 'state.map.zoom',
markers: 'state.map.markers',
draggable: 'true'}
以及定义状态的 DState Factory:
.factory 'DashboardState', (Media) ->
class DashboardState
defaults:
map:
center:
latitude: 45.764043
longitude: 4.835659
zoom: 10
markers: []
selectedObj: null
constructor: (initialData) ->
_(@defaults).extend initialData
_(this).extend @defaults
所以,我在 infoWindow 中的显示是
不应显示原因指令
但我应该有我的指令中的内容:
在指令中
我的指令没有被调用...你有什么想法吗?
这是一个双重问题,我想将我工厂的 SelectedObj 设置为 Obj 本人。您是否有想法如何处理标记上的事件单击以及将其放置在何处以调用可以将我的 obj 分配给 SelectedObj 的方法?
提前致谢
【问题讨论】:
-
我认为
没有通过角度重新评估来转换指令,它直接显示原始 html.. 我暂时还没有找到解决方案 -
如果您使用 $compile 手动编译该 html 字符串(用于 infowindow),然后将其绑定到范围会怎样。这应该有角度来处理指令。
标签: angularjs google-maps-api-3 google-maps-markers angularjs-directive