Search code examples
angularjstypescriptng-class

angular ng-class statement with multiple conditions


I have to assign a class or an other to a field according two condition, one is about the position (it does not have to be the last one), the second is about a boolean parameter in my controller (my project is written using typescript and angular 1)

So i use: ng-class="(ctrl.parameter || !$last) ? 'class1' : 'class2'" But it doesnt work. Someone can help me

Thanks


Solution

  • You can't use the ternary conditions in ng-class. it has to be like this

    ng-class="{true: 'class1', false: 'class2'}[(ctrl.parameter || !$last)]"
    

    Plunker https://embed.plnkr.co/Pj5aEh4O0xNiNrVv2fBU/