Search code examples
angularng-map

how to set ng-map marker visibility?


I am trying to set ng-map marker visibility option via html attribute. I've been struggling with about two hours. Thank you in advance.

<div ng-app="mapApp" ng-controller="mapController">
    <ng-map default-style="true" zoom="5" center="usa">

        <marker
                position="usa" options="{visible:false}">
        </marker>
    </ng-map>
</div>

Here is my fiddle https://jsfiddle.net/AlexLavriv/La52ggbw/1/


Solution

  • You can use ng-if to disable the marker

    <div ng-app="mapApp" ng-controller="mapController">
        <ng-map default-style="true" zoom="5" center="usa">
    
            <marker ng-if="showMarkers"
                    position="usa" options="{...}">
            </marker>
        </ng-map>
    </div>
    

    In your controller

    $scope.showMarkers=false;
    

    LIVE DEMO