Bird
0
0

Consider this facade service snippet:

medium📝 Predict Output Q5 of 15
Angular - Advanced Patterns

Consider this facade service snippet:

export class UserFacade {
  constructor(private userService: UserService) {}
  getUser() { return this.userService.getUserData(); }
}

What happens if userService is not provided in any module?

AThe facade service creates a new instance automatically.
BThe facade service works but returns undefined.
CAngular throws a runtime error about missing provider.
DAngular silently ignores the missing service.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Angular dependency injection

    Services must be provided to be injected; otherwise Angular errors at runtime.
  2. Step 2: Identify behavior when provider is missing

    Missing provider causes Angular to throw an error about no provider found.
  3. Final Answer:

    Angular throws a runtime error about missing provider. -> Option C
  4. Quick Check:

    Missing provider = runtime error [OK]
Quick Trick: Always provide services to avoid injection errors [OK]
Common Mistakes:
  • Assuming Angular auto-creates missing services
  • Expecting undefined instead of error
  • Thinking Angular ignores missing providers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes