Search code examples
angularjsng-class

multiple function calls inside ngClass


I want to apply multiple classes using ng-class like

ng-class="func1();function2()"  

This throws an error.

Do I have to write complete in one function only?

Can I not call two functions like above or any proper syntax to do the same.


Solution

  • Assuming both functions returns a class name, you should be able to do:

    ng-class="func1() + ' ' + function2()"
    

    However it does smell a little bit. I much rather prefer to set up a watcher to update classes property on scope (or on controller if you use controllerAs).