Bird
0
0

Why might using ngClass with a falsy value like 0 or '' cause unexpected class application?

hard📝 Conceptual Q10 of 15
Angular - Directives
Why might using ngClass with a falsy value like 0 or '' cause unexpected class application?
AFalsy values are treated as true and add the class
BFalsy values convert to string and add class literally
CFalsy values are ignored and do not add the class
DFalsy values cause runtime errors in ngClass
Step-by-Step Solution
Solution:
  1. Step 1: Understand how ngClass treats falsy values

    In ngClass, keys with falsy values like 0, '', false, null, or undefined are ignored and their classes are not added.

  2. Step 2: Check implications

    This prevents unwanted classes from being applied when the condition is falsy.

  3. Final Answer:

    Falsy values are ignored and do not add the class -> Option C
  4. Quick Check:

    Falsy values skip class addition [OK]
Quick Trick: Falsy values in ngClass skip adding classes [OK]
Common Mistakes:
  • Thinking falsy values add classes
  • Expecting errors from falsy values
  • Confusing falsy with string 'false'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes