Bird
0
0

You want to bootstrap an Angular app with a standalone component that uses a service. Which is the correct way to provide the service during bootstrapping?

hard📝 Application Q15 of 15
Angular - Standalone Components
You want to bootstrap an Angular app with a standalone component that uses a service. Which is the correct way to provide the service during bootstrapping?
AInject the service directly in main.ts without providers
BPass the service in the providers array inside the component decorator only
CDeclare the service in an NgModule and bootstrap with bootstrapModule
DPass the service in the providers option of bootstrapApplication call
Step-by-Step Solution
Solution:
  1. Step 1: Understand service provision with standalone bootstrap

    When bootstrapping standalone components, you can provide services via the providers option in bootstrapApplication.
  2. Step 2: Compare options

    Providing services only in the component decorator limits scope; providing in bootstrapApplication makes them app-wide.
  3. Final Answer:

    Pass the service in the providers option of bootstrapApplication call -> Option D
  4. Quick Check:

    Use providers in bootstrapApplication for app-wide services [OK]
Quick Trick: Use providers option in bootstrapApplication for services [OK]
Common Mistakes:
  • Providing services only in component decorator limits scope
  • Using NgModule approach with standalone bootstrap
  • Injecting services without providers causes errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes