1

In this line of code:

<p>{{ data.length > 0 && 'My data' || 'No data' }}</p>

what does the && and || mean?

At first I thought that these were boolean functions. The equivalent in Java or C# would be an inline IF statement:

<p>{{ data.length > 0 ? 'My data' : 'No data' }}</p>

But that statement doesn't work in AngularJS.

1 Answer 1

4

The second statement actually does work in the new angularjs, the first one was just a workaround before it was implemented.

The && and || function exactly the same as the do an if statement. So you can use that outside of angular as well. Just like this:

console.log(4 > 3 && 'true' || 'false');
Sign up to request clarification or add additional context in comments.

3 Comments

Except that in most programming languages && means AND and || means OR.
You're right about the inline IF statement. I updated my AngularJS library and it works.
It still does mean that in javascript. If(4 > 5 && 2 > 1 || 3 > 1) is completely valid

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.