Bird
0
0

Why does this service cause multiple instances?

medium📝 Debug Q7 of 15
Angular - State Management
Why does this service cause multiple instances?
@Injectable()
export class UserService {}

@Component({
  selector: 'app-user',
  providers: [UserService]
})
export class UserComponent {}
ABecause UserService is not imported in module
BBecause @Injectable decorator is missing providedIn
CBecause UserService is provided in component providers, not root
DBecause selector is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check where service is provided

    UserService is provided in component's providers array.
  2. Step 2: Understand effect on instances

    Providing in component creates a new instance per component, not singleton.
  3. Final Answer:

    Because UserService is provided in component providers, not root -> Option C
  4. Quick Check:

    Component providers = multiple instances [OK]
Quick Trick: Provide services in root for singleton [OK]
Common Mistakes:
  • Assuming @Injectable alone makes singleton
  • Ignoring providers array location
  • Confusing selector with service scope

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes