🧱 Understanding Angular Components in Angular 20 β€” The Building Blocks of Every App

Tushar JadhavTushar Jadhav
3 min read

Welcome back to The Debug Diaries! πŸ‘‹
In the last post, we created our first Angular 20 app using the CLI.

Now, let’s dive into the most important concept in Angular: Components.
In Angular 20, components are simpler β€” file names like example.ts, example.html, etc., make them easier to read and manage.


πŸ” What is a Component?

In Angular, a component is like a mini building block for your app. Each piece of the screen (header, card, form, etc.) can be its own component.

It contains:

  • 🧠 Logic β†’ TypeScript

  • πŸ–ΌοΈ Template β†’ HTML

  • 🎨 Styling β†’ CSS


πŸ—‚οΈ A Simple Component Structure (Angular 20 Style)

When you create a component like this:

ng generate component welcome

Angular 20 creates these 4 files:

src/app/welcome/
β”œβ”€β”€ welcome.ts         ← logic file (was .component.ts earlier)
β”œβ”€β”€ welcome.html       ← template file
β”œβ”€β”€ welcome.css        ← styles for this component
└── welcome.spec.ts    ← test file (you can ignore this for now)

No more welcome.component.ts β€” just clean, simple filenames.


✨ Let’s See an Example

🧠 welcome.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-welcome',
  templateUrl: './welcome.html',
  styleUrls: ['./welcome.css']
})
export class Welcome {
  username = 'Tushar';
}

πŸ–ΌοΈ welcome.html

<h2>Welcome to Angular 20, {{ username }}!</h2>

🎨 welcome.css

h2 {
  color: #1976d2;
  font-weight: 600;
  font-family: 'Segoe UI', sans-serif;
}

πŸ’‘ How Does Angular Know About Your Component?

When you generate a component, Angular automatically registers it in app.module.ts:

import { Welcome } from './welcome/welcome';

@NgModule({
  declarations: [
    AppComponent,
    Welcome
  ],
})
export class AppModule { }

Once it's declared, you can use <app-welcome></app-welcome> in your app’s template to show it.


πŸ› οΈ Want to Create Another Component?

Use this command:

ng generate component contact

It will generate:

  • contact.ts

  • contact.html

  • contact.css

  • contact.spec.ts

Quick and clean!


βœ… Recap

  • Angular 20 uses simplified component filenames (.ts, .html, .css)

  • Each component contains logic, layout, and styling

  • Components are the building blocks of your Angular apps


πŸ“Œ What’s Next?

In the next blog on The Debug Diaries, we’ll cover:

πŸ”— Data Binding in Angular 20
You’ll learn how to connect your data to the UI using:

  • Interpolation ({{ }})

  • Property Binding ([ ])

  • Event Binding (( ))

Stay tuned and keep debugging with me!


πŸ”— Let's Connect and Explore More!

πŸ“– Read the full series: ngtushar.hashnode.dev/angular-series
πŸ’» Source Code on GitHub: github.com/Tushar1409-hj
πŸ”— Connect with me on LinkedIn: linkedin.com/in/tushar1409

If you found this post helpful, don’t forget to share it with your fellow developers and follow the series for more Angular insights! πŸš€

0
Subscribe to my newsletter

Read articles from Tushar Jadhav directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tushar Jadhav
Tushar Jadhav