How to use relative path in Angular Google Maps directives?

徘徊边缘 提交于 2020-01-05 02:23:05

问题


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>

This code throws the following error:

Error: [$parse:syntax] Syntax Error: Token '.' not a primary expression at column 1 of the expression [../img/marker-map.png] starting at [../img/marker-map.png].

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?


回答1:


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>

On my controller:

$scope.markerIcon = "img/marker-map.png";


来源:https://stackoverflow.com/questions/24144265/how-to-use-relative-path-in-angular-google-maps-directives

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!