首页 > 解决方案 > 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

标签: angularjstypescriptng-class

解决方案


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/


推荐阅读