Bird
0
0

You want to share user login status across multiple components and keep UI code simple. Which approach best uses Angular services?

hard🚀 Application Q15 of 15
Angular - Services and Dependency Injection
You want to share user login status across multiple components and keep UI code simple. Which approach best uses Angular services?
AUse local variables in components without services
BStore login status in each component separately
CCreate a UserService with login status and methods, inject it in components
DWrite login logic inside each component's template
Step-by-Step Solution
Solution:
  1. Step 1: Identify need for shared state

    Login status must be shared and consistent across components.
  2. Step 2: Choose best practice

    Using a UserService to hold login state and methods keeps components simple and shares data.
  3. Final Answer:

    Create a UserService with login status and methods, inject it in components -> Option C
  4. Quick Check:

    Use service to share state and logic [OK]
Quick Trick: Use services to share app state and logic [OK]
Common Mistakes:
MISTAKES
  • Duplicating state in components
  • Putting logic in templates
  • Avoiding services for shared data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes