1

I have a Google Map, with markers that I want to toggle on and off.

<marker id='{{marker.id}}   'visible="{{ condition ? 'true' : 'false'}}">
</marker>

And I made a button for toggling it off

<button ng-click="condition = false" ng-init="condition = true">
     Toggle visibility
</button>

How do I make it switch between toggling the condition true/false, on the same click?

Or maybe using a toggle functionality.

Marc Hjorth
  • 1,797
  • 2
  • 18
  • 24

2 Answers2

1

just use ng-show and invert condition variable on button click

<marker id='{{marker.id}}   ng-if="condition"></marker>
<button ng-click="condition = !condition" ng-init="condition = true">Toggle visibility</button>
Bo Vandersteene
  • 601
  • 7
  • 16
Shaybi
  • 318
  • 2
  • 9
1
<marker id='{{marker.id}}   ng-if="condition"></marker>
<button ng-click="condition = !condition" ng-init="condition = true">Toggle isibility</button>

Use ng-if over ng-show, this is another discussion When to favor ng-if vs. ng-show/ng-hide?

Community
  • 1
  • 1
Bo Vandersteene
  • 601
  • 7
  • 16