角度ng-class如果这个和那个,if-else表达式

sim*_*ple 1 angularjs

如何编码?

If >= 5 myClass1
else if
< 5 myClass2
else if
< 5 and <=2 myClass3
Run Code Online (Sandbox Code Playgroud)

这部分工作正常:$ index> = 5?'hidden-md col-lg-1':

需要解决这个问题:(($ index <= 2?'col-md-4 col-lg-2'):'col-md-2 col-lg-2')

ng-class="$index >= 5 ? 'hidden-md col-lg-1' : (($index <= 2 ? 'col-md-4 col-lg-2') : 'col-md-2 col-lg-2')"
Run Code Online (Sandbox Code Playgroud)

sp0*_*00m 5

您也可以使用对象表示法:

ng-class="{
    'hidden-md col-lg-1': $index >= 5,
    'col-md-2 col-lg-2': $index < 5 && $index > 2,
    'col-md-4 col-lg-2': $index <= 2,
}"
Run Code Online (Sandbox Code Playgroud)