Angular · Middle · Question 22 of 75
What happens when a component lists a service in its providers?
@Component({ selector: "app-editor", providers: [EditorState] })- ✓Correct answer: Each
app-editorinstance gets its ownEditorState, shared with its children - 2The service becomes a global singleton
- 3The service is created once and shared by all editor instances
Explanation
Component providers create an element injector. Each component instance and its subtree get a separate instance, which is great for per-widget state; it is destroyed with the component.