0

I'm trying to use the arguments of an ng-click to add a class to the same element, but so far no luck.

What I'm doing wrong? Basically what I want to do is to add a certain class to the element when clicked. Right now, on ng-click, i'm declaring answer="yes".

Here's my code:

<div class="col-md-8 col-md-offset-2" ng-switch on="answer">

    <div class="row question">Do you like to travel?</div>

    <div class="row">
      <div class="col-md-12">
        <div class="col-md-6">
          <a class="btn col-md-12" ng-click="answer='yes'" ng-class="answer='yes' : 'active'" >Yes</a>
        </div>
        <div class="col-md-6">            
          <a class="btn col-md-12" ng-click="answer='no'">No</a>
        </div>  
      </div>
    </div>
</div>

1 Answer 1

1

The correct syntax would be:

ng-class="{'active' : answer == 'yes'}"
Sign up to request clarification or add additional context in comments.

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.