Bird
0
0

What will be the output of this Angular component code snippet that manages state locally without NgRx?

medium📝 Predict Output Q5 of 15
Angular - State Management
What will be the output of this Angular component code snippet that manages state locally without NgRx?
export class ToggleComponent {
  isOn = false;
  toggle() {
    this.isOn = !this.isOn;
  }
}

{{ isOn ? 'ON' : 'OFF' }}


After clicking the button once, what is displayed?
AON
BOFF
Ctrue
Dfalse
Step-by-Step Solution
Solution:
  1. Step 1: Initial state is false

    isOn starts as false, so display is 'OFF'.
  2. Step 2: Toggle flips isOn

    After one toggle, isOn becomes true, so display is 'ON'.
  3. Final Answer:

    ON -> Option A
  4. Quick Check:

    Toggle flips false to true = 'ON' [OK]
Quick Trick: Toggle flips boolean state each click [OK]
Common Mistakes:
  • Expecting string 'true' instead of 'ON'
  • Forgetting initial state value
  • Confusing toggle logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes