Angular Components Created: 06 Jan 2026 Updated: 06 Jan 2026

The Anatomy of an Angular Component

A standard Angular component consists of a TypeScript class, an HTML template, and CSS styles. The heart of this structure is the TypeScript file, typically named app.component.ts.

Here is what a basic component looks like in a modern Angular project:

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

@Component({
selector: 'app-root',
imports: [RouterOutlet],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})
export class AppComponent {
title = 'World';
}


The Role of the @Component Decorator

The @Component decorator is a function that marks a TypeScript class as an Angular component. It provides metadata—the configuration that tells Angular how to handle the class. Without this decorator, the class is just a plain TypeScript object.

Let’s examine the key properties found within the metadata object:

1. selector

The selector defines the CSS tag that Angular uses to "instantiate" this component. For example, if the selector is 'app-root', you can use <app-root></app-root> in your HTML files, and Angular will render the component at that location. By default, the Angular CLI prefixes selectors with app-, though this can be customized during project setup.

2. imports

This property is the cornerstone of modern Angular. It defines the external dependencies (like other components, directives, or pipes) that this specific component needs to function.

  1. In the example above, RouterOutlet is imported to enable routing capabilities.
  2. In earlier versions, these dependencies were managed in an NgModule. Now, the component is self-contained.


3. templateUrl and styleUrl

These properties link the logic of the component to its visual representation:

  1. templateUrl: The path to an external HTML file. Alternatively, you can use the template property to write HTML directly inside the decorator.
  2. styleUrl: The path to an external CSS file. Similarly, you can use styles for inline styling.


The Evolution: From Modules to Standalone Defaults

The structure of Angular components has undergone a significant transformation in recent years:

  1. Before Angular v16: Components heavily relied on NgModules (Angular Modules) to manage dependencies. This often led to "boilerplate" code that was difficult for beginners to navigate.
  2. Angular v16 & v17: The standalone: true property was introduced, allowing components to exist without being declared in a module.
  3. Angular v19: Standalone components are now the enforced default. The standalone: true flag is often omitted because it is assumed. The imports array is now the standard way to bring in functionality, marking a permanent departure from the module-based architecture.


Share this lesson: