CHAPTER 17
Beginner
Component Communication
Updated: May 18, 2026
5 min read
# CHAPTER 17
Component Communication
1. Chapter Introduction
In a real Angular app, components cannot live in isolation. A parent component may pass a user object down to a child profile card. A child delete button may need to notify the parent to remove an item. Components need structured communication channels. Angular provides three main patterns:@Input, @Output with EventEmitter, and service-based (shared state) communication.
2. Learning Objectives
-
Pass data from parent to child using
@Input.
-
Send events from child to parent using
@OutputandEventEmitter.
- Share state between non-related components using a Service.
-
Understand
@ViewChildfor direct child access.
3. @Input — Parent to Child
parent.component.ts
html
product-card.component.ts
4. @Output — Child to Parent
delete-btn.component.ts
html
parent.component.ts
5. Service-Based Communication (Siblings)
When two components have no direct parent-child relationship, a shared service with aSubject or BehaviorSubject is the clean solution:
notification.service.ts
sender.component.ts
receiver.component.ts
6. @ViewChild — Direct Child Access
typescript
7. Communication Pattern Summary
text
8. Common Mistakes
-
Mutating
@Inputdata directly: Never modify an@Inputproperty inside the child component. This breaks data flow and causes unpredictable bugs. Instead, emit an event and let the parent handle the change.
-
EventEmitterfor non-component communication:EventEmitteris designed for template events only. For service-to-service or sibling communication, use RxJSSubject.
9. MCQs with Answers
Question 1
Which decorator allows a child component to receive data from its parent?
Question 2
Which decorator allows a child component to emit events to its parent?
Question 3
What class is used alongside @Output to emit events?
Question 4
In (itemDeleted)="handleDelete($event)", what does $event contain?
Question 5
What is the best pattern for communication between two sibling components with no parent-child relationship?
Question 6
What decorator gives a parent direct access to a child component instance?
@Input property inside the child component?
a) Yes b) No — emit an event via @Output and let the parent handle modification
Answer: b) No — use @Output.
Question 8
When is @ViewChild available to use?
Question 9
How do you pass a string "hello" from parent to a child's @Input() message property?
Question 10
What is the recommended solution for app-wide state sharing between many unrelated components?
10. Interview Questions
-
Q: Explain the difference between
@Input/@Outputand service-based communication. When would you choose one over the other?
-
Q: What is the difference between
SubjectandBehaviorSubjectfor component communication?
11. Summary
Angular's component communication system is elegant and predictable.@Input creates a data downflow from parent to child. @Output creates an event upflow from child to parent. Services with RxJS Subjects bridge the gap for any other communication scenario. Following these patterns strictly keeps your component architecture clean and decoupled.