Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS ng-class multiple conditions

Tags:

angularjs

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

like image 357
MChan Avatar asked Apr 05 '14 22:04

MChan


2 Answers

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.

like image 190
Billy Moon Avatar answered Oct 11 '22 05:10

Billy Moon


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}"
like image 41
dave Avatar answered Oct 11 '22 05:10

dave