Bird
0
0

Identify the issue in this Angular template snippet:

medium📝 Debug Q6 of 15
Angular - Directives
Identify the issue in this Angular template snippet:
<div [ngClass]="{ active: isActive, disabled }"></div>

Assuming isActive is a boolean variable.
AThe syntax is correct and will work as expected
BThe object literal is missing a value for the 'disabled' key
CThe keys should be strings in quotes
DngClass cannot accept object literals
Step-by-Step Solution
Solution:
  1. Step 1: Analyze object literal syntax

    In JavaScript, object keys must have values. Here, 'disabled' has no value assigned.
  2. Step 2: Understand ngClass input

    ngClass expects an object with keys as class names and boolean values indicating whether to apply them.
  3. Final Answer:

    The object literal is missing a value for the 'disabled' key -> Option B
  4. Quick Check:

    Object keys must have values in ngClass [OK]
Quick Trick: Every key in ngClass object must have a value [OK]
Common Mistakes:
  • Omitting values for keys in object literal
  • Assuming keys alone apply classes
  • Using invalid object syntax in template

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes