Angular @Input
Learn how to use @Input to pass data from a parent component to a child component in Angular.
What is @Input?
In Angular, @Input is used when a parent component needs to send data to a child component.
The parent component provides the data using property binding, while the child component receives that data through an Input property.
This creates a simple and controlled way for components to communicate from Parent → Child.
Parent to Child Communication
Basic @Input Syntax
<app-course-card
[courseName]="selectedCourse">
</app-course-card>
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-course-card',
templateUrl: './course-card.component.html'
})
export class CourseCardComponent {
@Input() courseName = '';
}
How @Input Works
Parent Has Data
The parent component contains the value that needs to be shared.
Property Binding
The value is passed using Angular property binding.
Child Receives Data
The child component receives the value through @Input.
Child Uses Data
The child can display or process the received value.
Simple @Input Example
export class CourseComponent {
selectedCourse = 'Full Stack .NET';
}
<app-course-card
[courseName]="selectedCourse">
</app-course-card>
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-course-card',
templateUrl: './course-card.component.html'
})
export class CourseCardComponent {
@Input() courseName = '';
}
<div class="course-card">
<h3>{{ courseName }}</h3>
<p>
Welcome to CIIT Training Institute.
</p>
</div>
Output
Full Stack .NET
Welcome to CIIT Training Institute.
Using Property Binding with @Input
The square bracket syntax [property] is used to bind a parent component property to a child component Input.
<app-course-card
[courseName]="selectedCourse">
</app-course-card>
Multiple @Input Properties
A child component can receive multiple values from its parent component.
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-course-card',
templateUrl: './course-card.component.html'
})
export class CourseCardComponent {
@Input() courseName = '';
@Input() duration = '';
@Input() fees = 0;
@Input() onlineAvailable = false;
}
<app-course-card
[courseName]="course"
[duration]="duration"
[fees]="fees"
[onlineAvailable]="online">
</app-course-card>
Complete CIIT Training Institute Example
Suppose the CIIT Training Institute course page has a parent component containing course information.
That information can be passed to a reusable course-card child component using multiple @Input properties.
export class CoursesComponent {
course = 'Java Full Stack';
duration = '6 Months';
fees = 35000;
online = true;
}
<app-course-card
[courseName]="course"
[duration]="duration"
[fees]="fees"
[onlineAvailable]="online">
</app-course-card>
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-course-card',
templateUrl: './course-card.component.html'
})
export class CourseCardComponent {
@Input() courseName = '';
@Input() duration = '';
@Input() fees = 0;
@Input() onlineAvailable = false;
}
<div class="course-card">
<h3>{{ courseName }}</h3>
<p>
Duration: {{ duration }}
</p>
<p>
Fees: ₹{{ fees }}
</p>
<p>
Online Training:
{{ onlineAvailable ? 'Available' : 'Not Available' }}
</p>
</div>
Different Types of Data
| Data Type | Input Example | Purpose |
|---|---|---|
| String | @Input() courseName = '' | Course name or text |
| Number | @Input() fees = 0 | Course fees |
| Boolean | @Input() onlineAvailable = false | True / False values |
| Object | @Input() course = { } | Multiple related values |
| Array | @Input() topics = [ ] | List of topics |
Important Points
@Input is mainly used for passing data from a parent component to a child component.
Use square brackets such as [courseName] when binding dynamic values.
Passing data through Inputs allows the same child component to be reused with different values.
Input property names should clearly describe the data being received.
@Input Best Practices
- Use @Input for Parent → Child communication.
- Use meaningful Input property names.
- Keep child components focused and reusable.
- Use property binding for dynamic values.
- Keep data flow clear between components.
- Avoid unnecessary duplicate data in child components.
Summary
Angular @Input allows a parent component to send data to a child component. The parent uses property binding, while the child receives the value through an Input property. This makes Angular components reusable and keeps communication between components organized.