Search code examples
angularjsangularjs-directiveng-class

Injecting class name and toggling class name Angular


I am aware that in angular you can do something like this:

<div ng-class="{myClassName: myCondition}"></div>

and Angular will add 'myClassName' to the class attribute if the condition is true.

I am also aware that:

<div ng-class="myClassName"></div>

will evaluate my 'myClassName' scope value and add it to the element's class argument.

Is there a way to do both of these at the same time on an element? If so, how?


Solution

  • I don't know if I understand you right,

    <div ng-class="{myClassName: true}" class="{{myOtherClassName}}"></div>
    

    controller

     $scope.myOtherClassName = "someClass";
    

    The result should be:

    <div   class="someClass myClassName"></div>