MChan
MChan

Reputation: 7162

AngularJS ng-class multiple conditions

I am trying to apply a specific class to an li element if 2 conditions are true, so I wrote the following code but it is not seem to be working

ng-class="{current:isActive('/'), loginStatus: false}"

Can someone please tell me what I am doing wrong and how to fix it so that the class is applied only if route is at / and loginstatus is false? Thanks

Upvotes: 6

Views: 19147

Answers (2)

dave
dave

Reputation: 64657

Right now it is set up to add the class current if isActive('/') return true, and the class loginStatus if false is true (which it, obviously, never will be).

What you need to do, to add the class current if isActive('/') AND loginStatus == false, is simply

ng-class="{current:isActive('/') && !loginStatus}"

Upvotes: 2

Billy Moon
Billy Moon

Reputation: 58521

The key should define the class you want, and the rest should be the expression to evaluate, which determines if the class is shown...

ng-class="{current:isActive('/') && loginStatus === false}"

What you were saying was more like... set class current if isActive('/') and also set class loginStatus if false is true.

Upvotes: 9

Related Questions