11.) When should you use hierarchical injectors in Angular?
A) When services should have different instances in different modules
B) When you want a service to be globally available
C) When injecting third-party libraries
D) When using @Component decorators
12.) What happens if a service is provided in both root and a module?
A) Angular throws an error
B) It affects all other services
C) The global instance is used
D) A new instance is created for the module
13.) How can a service be limited to a specific module?
A) Using { providedIn: ‘root’ }
B) Adding it in providers array of a module
C) Declaring it inside main.ts
D) Using @Component({ providers: [MyService] })
14.) What is an Angular Injector?
A) A tool to create components
B) A built-in function to modify services
C) A system that maintains dependencies and injects them where needed
D) A method to call services
15.) How do you prevent multiple instances of a service?
A) Use { providedIn: ‘root’ }
B) Create multiple service classes
C) Avoid using services
D) Manually create service instances
16.) Which lifecycle hook is best for initializing a service in a component?
A) ngAfterContentInit()
B) ngAfterViewInit()
C) ngOnDestroy()
D) ngOnInit()
17.) How can a service be injected at the component level instead of globally?
A) Declare it in @NgModule.providers
B) Use { providedIn: ‘root’ }
C) Add it in the providers array of @Component
D) Import it in app.module.ts
18.) What is the role of an Injector in Angular?
A) It handles the service creation and dependency injection
B) It compiles Angular components
C) It renders templates dynamically
D) It is responsible for module configuration
19.) What will happen if you manually create a new service instance inside a component?
A) It optimizes performance
B) It creates multiple instances, breaking singleton behavior
C) It improves service sharing
D) It has no impact
20.) What is an alternative way to inject dependencies manually?
A) Using Injector.get(MyService)
B) Using import { MyService }
C) Using new MyService()
D) By modifying the component template
Related