π§± Understanding Angular Components in Angular 20 β The Building Blocks of Every App

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! π
Subscribe to my newsletter
Read articles from Tushar Jadhav directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
