6

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

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I'd recommend === instead of ==
I think I remember that === became fashionable around the same time as the Gillette Mach III. Now there are razors with four blades, do you think javascript needs an ulta equality comparison symbol - ====?
@GonchuB - you are right of course - I changed it. But what about simply &! loginStatus - it is probably fine too no? Depends on what loginStatus can be.
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.