0

I can't figure out why this code doesn't work as a toggle. Any ideas what I might be doing wrong?

  <div ng-switch="!!myvar">
    <a ng-switch-when="false" ng-click="myvar = true" style="cursor:pointer">
      false
    </a>
    <a ng-switch-default ng-click="myvar = false" style="cursor:pointer">
      true
    </a>
  </div>

I'm using AngularJS 1.2.0-rc.2.

0

1 Answer 1

3

The directive ng-switch creates a new scope, so you need to use $parent to update the myvar in the parent scope.

<a ng-switch-when="false" ng-click="$parent.myvar = true" style="cursor:pointer">
<a ng-switch-default ng-click="$parent.myvar = false" style="cursor:pointer">
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.