Angular 22: Build Reusable Components with Signal Inputs and @for

Have you ever wondered how to display 12 restaurant cards in Angular without writing the same HTML 12 times?

The answer is reusable components and data binding.

In Part 02 of my FoodieAI project series, we're learning these Angular concepts by building a food delivery homepage.

This tutorial focuses on standalone components, Signal Inputs, parent-to-child communication, and Angular's modern @for control flow.

What We're Building

FoodieAI is an educational food delivery application built with Angular 22, TypeScript, Bootstrap 5, and eventually Groq AI integration.

In Part 02, we focus on:

  • Creating a homepage and public layout
  • Building reusable Angular components
  • Understanding TypeScript interfaces
  • Passing data from a parent to a child component
  • Rendering dynamic lists using @for
  • Using interpolation and property binding
  • Building responsive restaurant cards with Bootstrap 5

Let's understand the most important part with a simple example.

1. Define a Restaurant Interface

First, define the structure of our restaurant data.

restaurant.model.ts

export interface Restaurant { readonly id: string; readonly name: string; readonly rating: number; readonly cuisine: string; } 

A TypeScript interface helps describe the expected structure of our data.

For example, the restaurant name must be a string, and the rating must be a number.

This is a simplified teaching model. The complete FoodieAI application uses a more detailed Restaurant interface.

2. Create a Reusable Restaurant Component

We can generate a new component using Angular CLI:

ng generate component features/home/restaurant-card 

Now let's use Angular's modern Signal Input API.

restaurant-card.component.ts

import { Component, input } from '@angular/core'; import { Restaurant } from '../../../models/restaurant.model'; @Component({ selector: 'app-restaurant-card', standalone: true, imports: [], templateUrl: './restaurant-card.component.html', styleUrl: './restaurant-card.component.css' }) export class RestaurantCard { readonly restaurant = input.required<Restaurant>(); } 

What is input.required()?

In modern Angular, Signal Inputs allow a component to receive data from its parent.

The input.required<Restaurant>() declaration means the parent must provide a Restaurant value.

Unlike a regular property, a Signal Input is read by calling it like a function:

restaurant() 

This is one of the useful features of modern Angular component communication.

3. Display Restaurant Data Using Interpolation

Now open the component's HTML file.

restaurant-card.component.html

<article class="card h-100"> <div class="card-body"> <h3 class="h5 text-success"> {{ restaurant().name }} </h3> <p class="text-secondary"> {{ restaurant().cuisine }} </p> <span class="badge text-bg-success"> ★ {{ restaurant().rating }} </span> </div> </article> 

Here, {{ }} is Angular interpolation.

It allows us to display TypeScript values in an HTML template.

The Bootstrap classes provide the basic styling without custom CSS.

4. Pass Data from Parent to Child

Next, we'll use our reusable component inside the Home component.

home.component.ts

import { Component } from '@angular/core'; import { RestaurantCard } from './restaurant-card/restaurant-card.component'; import { Restaurant } from '../../models/restaurant.model'; @Component({ selector: 'app-home', standalone: true, imports: [RestaurantCard], templateUrl: './home.component.html', styleUrl: './home.component.css' }) export class Home { readonly restaurants: Restaurant[] = [ { id: '1', name: 'The Saffron Table', rating: 4.8, cuisine: 'Indian' }, { id: '2', name: 'Basil & Brick', rating: 4.7, cuisine: 'Pizza' } ]; } 

Now we have a parent component containing restaurant data and a child component responsible for displaying individual restaurants.

5. Render Multiple Cards Using @for

home.component.html

<section class="container py-4"> <h2 class="mb-4">Restaurants</h2> <div class="row g-3"> @for (restaurant of restaurants; track restaurant.id) { <div class="col-12 col-md-6 col-lg-4"> <app-restaurant-card [restaurant]="restaurant"> </app-restaurant-card> </div> } </div> </section> 

What happens here?

  1. Angular loops through the restaurants array.
  2. Each restaurant object is passed to the reusable child component.
  3. The RestaurantCard component displays that restaurant's information.
  4. The track restaurant.id expression helps Angular identify individual items efficiently.

The best part?

Whether we have 2 restaurants or 100, the same reusable component can display them without duplicating the card template.

6. Why Use Reusable Components?

Reusable components help us:

  • Reduce duplicate HTML
  • Keep application design consistent
  • Maintain code more easily
  • Separate responsibilities
  • Build scalable frontend applications

This approach is particularly useful for restaurant cards, product cards, dashboards, user profiles, and many other application features.

7. Watch the Full FoodieAI Tutorial

I've recorded a practical Hindi/Hinglish walkthrough explaining the complete FoodieAI Part 02 implementation, including the homepage, public layout, nested routing, reusable components, and data binding.

Previous Video — Part 01: Angular Project Setup

https://youtu.be/BFkGSg1Uef0

What's Next?

In the next FoodieAI tutorial, we'll move from hardcoded restaurant data to REST API integration using Angular's httpResource().

The complete series will gradually cover restaurant discovery, search, Signals, shopping cart, checkout, authentication, admin features, and Groq AI integration.

Let's Discuss!

Have you started using Angular Signal Inputs in your projects?

Do you prefer input.required() or traditional @Input()?

Share your experience in the comments!

Happy Coding!

— Testy Codeiz

Keep Practicing, Keep Coding!