Note: This article is published on 02/08/2025.
This series of articles will discuss the major feafures for Angular. The way to discuss could be AI in concept + Code Demo in StackBlitz | Instant Dev
Advanced:
Note (after writing this article):
Since the concept of component interaction here is with similar or same mechanizm or funcationality as view variable transfer data between MVC controllers, saytherefore, I put the other article series of View Variables in ASP.NET MVC here as references:
A - Introduction
Angular is a component based platform and all components make up the application. The major mechanizim for Angular is the data trasferting, either within a component or between (among) components. This article will discuss the data transfer between different Angular components.
The content of this article:
- Parent to Child (Using @Input())
- Child to Parent (Using
@Output()
and EventEmitter
)
- Sibling Components (Using a Shared Service)
- Parent Accessing Child with
@ViewChild()
- Using Local Storage / Session Storage
- Route Parameters (Passing Data via URL)
- Query Parameters
- Router State Transfer
- Using NgRx for Global State Management
- Angular Signals (Angular 16+)
In Angular, data transfer between components can be achieved in several ways, depending on the relationship between the components and the nature of the data. Here are the main approaches:
1. Parent to Child (Using @Input())
Use @Input()
decorator to pass data from a parent component to a child component.
Parent Component (HTML):
Parent Component (TypeScript):
Child Component (TypeScript):
Note: Detailed example, please see this: Angular Features (2-1) --- Component Interaction (1) by @Input/@Output
✅ Best for: Passing static data or objects from parent to child.
2. Child to Parent (Using @Output()
and EventEmitter
)
Use @Output()
and EventEmitter
to send data from child to parent.
Child Component (TypeScript)
Parent Component (HTML)
Parent Component (TypeScript)
Note: Detailed example, please see this: Angular Features (2-1) --- Component Interaction (1) by @Input/@Output
✅ Best for: When a child component needs to send events or data to its parent.
3. Sibling Components (Using a Shared Service)
Use a shared service with RxJS Subject or BehaviorSubject to enable communication between sibling components.
Shared Service (data.service.ts)
Component A (Sending Data)
Component B (Receiving Data)
✅ Best for: Sharing data between sibling components.
4. Parent Accessing Child with @ViewChild()
Use @ViewChild()
in a parent component to directly access the child component’s methods or properties.
Child Component
Parent Component
✅ Best for: When the parent needs to directly interact with the child component.
5. Using Local Storage / Session Storage
For persisting data across components and page reloads, use localStorage
or sessionStorage
.
Saving Data
Retrieving Data
✅ Best for: Storing temporary data that persists across page refreshes.
6. Route Parameters (Passing Data via URL)
Use Angular Router to pass data via route parameters.
Routing Module
Navigating with Data
Accessing Data in Component
✅ Best for: Passing dynamic values through the URL.
7. Query Parameters
Instead of route parameters, use query parameters.
Navigating with Query Params
Accessing Query Params
✅ Best for: Sending optional parameters via the URL.
8. Router State Transfer
Pass data without exposing it in the URL.
Navigating with State
Retrieving Data
✅ Best for: Transferring temporary data securely.
9. Using NgRx for Global State Management
For complex applications, NgRx provides a centralized state management solution.
Example
✅ Best for: Large-scale applications that require state management.
10. Angular Signals (Angular 16+)
If using Angular 16+, leverage signals for reactive state management.
✅ Best for: Modern, reactive state management.
Choosing the Right Method
- Parent → Child:
@Input()
- Child → Parent:
@Output()
- Sibling Components: Shared Service with
Subject
- Persisting Data:
localStorage
/ sessionStorage
- Across Routes: Route Parameters, Query Params, or Router State
- Global State: NgRx or Angular Signals
Let me know if you need more details! 🚀
Summary Table
![]()
References:
- ChatGPT: ways to transfer data in angular