Passing Data from Parent to Child with @Input Decorator in Angular
📖 Scenario: You are building a simple Angular app where a parent component sends a message to its child component. This is common when you want to reuse a child component but show different data inside it.
🎯 Goal: Build two Angular components: a parent and a child. The parent will pass a string message to the child using the @Input decorator. The child will display this message in its template.
📋 What You'll Learn
Create a child component with an
@Input property called message of type stringCreate a parent component that uses the child component selector in its template
Pass a string value from the parent component to the child component using property binding
Display the passed message inside the child component's template
💡 Why This Matters
🌍 Real World
Passing data from parent to child components is a common pattern in Angular apps to build reusable and dynamic UI parts.
💼 Career
Understanding @Input is essential for Angular developers to create modular components and manage data flow in applications.
Progress0 / 4 steps