0

I want to convert below piece of jquery code into angularjs.. Please help.

$('.favorite').click(function() 
{
  $(this).toggleClass('active');
});
1

2 Answers 2

0
<span ng-click="toggle()" ng-class="{active: isShown}">look at my class (working)</span><br>

in your controller

$scope.toggle = function () {
      $scope.isShown = !$scope.isShown
}
Sign up to request clarification or add additional context in comments.

Comments

0

You cant try this:

<button class="favorite" ng-click="state = !state" ng-class="{'active' : state}">Some text...</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.