simple
simple

Reputation: 2397

angular ng-class if this and that,if-else expression

How to code this?

If >= 5 myClass1
else if
< 5 myClass2
else if
< 5 and <=2 myClass3

This part works correctly: $index >= 5 ? 'hidden-md col-lg-1' :

Need to fix this: (($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')"

Upvotes: 1

Views: 486

Answers (1)

sp00m
sp00m

Reputation: 48807

You can probably use the object notation as well:

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,
}"

Upvotes: 5

Related Questions