0

I am trying to remove all classes "fa-3x " and change all classes to "fa-lg" and add a class called="testClass", when the user click on class toggle-button. is it possible to do it in angular? really appreciate. your help

I know in jquery it very simple using add class and removeClass. can someone show me How to do it in angular?

  <div ng-controller="MainContainerController" ng-Click="toggleClass()">
        <ul class="nav" >
            <li>
                <a class="toggle-button"><i class="fa fa-exchange"></i></a>
            </li>
            <li>
                <a ui-sref="Home" ng-class="ActiveMenu('Home')">
                   <i class="fa fa-home fa-3x"></i>
                   <span>Home</span>
                </a>
            </li>
            <li>
                <a ng-class="ActiveMenu('Work')"> 
                   <i class="fa fa-bar-chart-o fa-3x"></i>
                   <span>Work </span>
                </a>
            </li>
            <li>
                <a ui-sref="Music" ng-class="ActiveMenu('Music')">
                   <i class="fa fa-table fa-3x"></i>
                   <span>Scenario <br/>Music</span>
                </a>
            </li>
            <li>
                <a ui-sref="faq">
                   <i class="fa fa-faq fa-3x"></i>                           
                   <span>Faq</span> 
                </a>
            </li>
       </ul>
  </div>
2
  • I was going to recommend taking a look at ng-class, but you're already using that on a different element. That's the directive to use for dynamically setting classes based on model values. Commented Apr 8, 2015 at 17:30
  • look at this entry stackoverflow.com/questions/20460369/… Commented Apr 8, 2015 at 17:33

2 Answers 2

1

Instead of using a function, I would recommend to use ng-class="{class1:(someVariable=='Workbench')} ng-class="{class2:(someVariable=='Music')}" While in function toggleClass() you can setup someVariable to 'Home', 'Workbench' etc.

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

Comments

0

user can use ng-class directive

<div  ng-click="changeClass()">
    <p ng-class="{'clicked':clicked,'not-clicked':!clicked}">Test</p>
    <p ng-class="{'clicked':clicked,'not-clicked':!clicked}">Test</p>

</div>
$scope.changeClass = function(){

    $scope.clicked = true;

};

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.