How to use relative path in Angular google maps directives?

I am trying to set a custom marker on a Google AngularJS 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 causes 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].

In the Angular Google Maps API documentation, the Marker icon directive parameter says:

An expression that returns the absolute path to the image used as a marker icon

I think I misunderstood this expression. Can't set the relative path for the marker icon image, as in the above code example? What could be an expression to reference a marker image?

+2
source share
1 answer

I got it, in the marker pointer icon parameter I should use a variable that refers to the marker image.

HTML:

 <marker ng-repeat="marker in markers" coords="marker" icon="markerIcon"> </marker> 

On my controller:

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

Source: https://habr.com/ru/post/1205578/


All Articles