Bird
0
0

You want to keep track of a user's login status and update the UI reactively in Angular. Which approach best uses state management to achieve this?

hard📝 Application Q15 of 15
Angular - State Management
You want to keep track of a user's login status and update the UI reactively in Angular. Which approach best uses state management to achieve this?
AUse a global variable and manually refresh components when it changes.
BUse a service without any reactive state to hold login info.
CStore login status in localStorage and read it only on page load.
DCreate a signal for login status and update it with set() on login/logout events.
Step-by-Step Solution
Solution:
  1. Step 1: Identify reactive state management for UI updates

    Using a signal to hold login status allows Angular to update UI automatically when state changes.
  2. Step 2: Compare other options

    Global variables or localStorage do not provide reactive updates; services without reactive state miss automatic UI refresh.
  3. Final Answer:

    Create a signal for login status and update it with set() on login/logout events. -> Option D
  4. Quick Check:

    Reactive signals = automatic UI updates [OK]
Quick Trick: Use signals with set() for reactive UI state changes [OK]
Common Mistakes:
  • Using global variables without reactivity
  • Relying only on localStorage without reactive updates
  • Ignoring reactive services or signals

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes