如何在 Angular Google Maps 指令中使用相对路径? [英] How to use relative path in Angular Google Maps directives?
问题描述
我正在尝试在 AngularJS 谷歌地图上设置自定义标记:
I'm trying to set a custom marker on an AngularJS Google Map:
<google-map
draggable="true"
style="display:block; width: 100%; height:100%;">
<markers>
<marker ng-repeat="marker in markers" coords="marker" icon="../img/marker-map.png">
</marker>
</markers>
</google-map>
此代码抛出以下错误:
错误:[$parse:syntax] 语法错误:标记."不是从 [../img/marker-map.png] 开始的表达式 [../img/marker-map.png] 的第 1 列的主要表达式.
在 Angular Google Maps API 文档上,在 Marker 指令的 icon
参数,它说:
On the Angular Google Maps API documentation, in Marker directive's icon
parameter , it says:
返回用作标记的图像的绝对路径的表达式图标
Expression returning the absolute path to an image used as the marker icon
我想我误解了那句话.是否可以像上面的代码示例一样为标记图标图像设置相对路径?引用标记图像的表达式是什么?
I think I misunderstood that statement. Isn't it possible to set a relative path for the marker icon image, as in the code example above? What could be an expression to reference the marker image?
推荐答案
我明白了,在标记指令的图标参数上,我应该使用一个引用标记图像的变量.
I got it, on the marker directive's icon parameter I should use a variable that references the marker image.
HTML:
<marker ng-repeat="marker in markers" coords="marker" icon="markerIcon">
</marker>
在我的控制器上:
$scope.markerIcon = "img/marker-map.png";
这篇关于如何在 Angular Google Maps 指令中使用相对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!