How to use relative path in Angular Google Maps di

2019-07-24 20:14发布

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条回答
Bombasti
2楼-- · 2019-07-24 20:38

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";
查看更多
登录 后发表回答