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.

1
  • 1
    Use condition = !condition as the value for the ng-click attribute Commented Dec 16, 2016 at 12:56

2 Answers 2

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?

Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.