October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

What Are the Parts of an Angular Component?

An Angular component connects a TypeScript class, an HTML template and a selector through @Component metadata. Learn how those parts fit together and where styles, imports and optional APIs belong.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An Angular component’s core consists of a TypeScript class, an HTML template and a CSS selector, configured with the @Component decorator. The class defines behavior, the template describes rendered content, and the selector identifies where the component is used. Styles and other metadata can extend that foundation, but they are not required parts of every component.

The three core parts of a component

Angular’s component guide describes a component through its class, template and selector. The @Component decorator connects these pieces by supplying metadata to Angular.

As an Amazon Associate I earn from qualifying purchases.

TypeScript class: behavior

The class contains the component’s logic—for example, handling user input or requesting data. Angular associates the class with its template and configuration through the decorator placed above it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

HTML template: rendered content

The template defines the DOM Angular renders for the component. It can be written directly in the component metadata using template, or kept in a separate HTML file referenced by templateUrl. Templates combine HTML with Angular features such as data bindings and event listeners; Angular compiles them into JavaScript. See the official templates guide.

Selector: where the component is used

The selector is a CSS selector that identifies the component in another template. For example, a parent template can contain an element matching a child component’s selector. Angular matches selectors statically at compile time: changing the DOM at runtime does not cause Angular to rematch components, and one element can match exactly one component selector. Details are in the selector guide.

What the @Component decorator configures

The object passed to @Component is metadata. It connects the class to its selector and template and can also specify styles and optional configuration. The Component API reference documents further options, including imports, inputs, outputs, providers, host bindings and queries.

Styles and encapsulation

Styles are optional. They can be supplied inline or from an external file and normally apply to elements in that component’s template. Angular supports Emulated, None and browser-native ShadowDom encapsulation policies. The compiler default is Emulated unless it is overridden.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How a component appears inside another component

To use a component in another standalone component, add the child component to the parent’s @Component metadata imports, then place an element matching the child’s selector in the parent template. Angular creates a component instance for each matching element.

The matching element is the child component’s host element. The DOM rendered from the child’s template is its view. Components nested this way form a component tree. Angular’s components essentials and components tutorial demonstrate this composition.

Standalone and NgModule-based components

Current Angular components are standalone by default. A standalone component lists the components, directives and pipes its template uses in its imports metadata.

The default changed in Angular 19: before version 19.0.0, standalone defaulted to false. In older NgModule-based projects, a non-standalone component is made available through its NgModule rather than by importing it directly into a standalone parent. When reading an older codebase, check the project’s Angular version and whether the component is standalone before looking for template dependencies.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Optional features that expand a component

These features can shape a component’s public API or behavior, but they are not required parts of every component:

  • Inputs let a component receive data through properties updated by Angular.
  • Outputs expose event emissions that templates can listen for.
  • Providers and queries configure dependency provision and access to relevant elements or directives.
  • Host bindings connect component state with properties or behavior on its host element.
  • Lifecycle hooks let a component respond at points in its creation, rendering, checking and destruction.

Angular checks bindings by traversing the application tree from top to bottom. Do not rely on a fixed ordering between a component lifecycle hook and a directive hook on the same element; Angular says that ordering is not guaranteed. See the lifecycle guide.

Host directives offer another optional composition mechanism. When a directive is applied through hostDirectives, its selector is ignored. Its inputs and outputs are not exposed through the component by default; map them explicitly when they should be part of the component’s public API. See Angular’s directive composition guide.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.