Common API Overview
The@angular/common package contains the common directives, pipes, and utilities that are essential for building Angular applications. This package provides the building blocks for template-driven UI manipulation and data transformation.
What’s in Common?
The Common package includes:- Structural Directives: Control the DOM structure conditionally and iteratively
- Attribute Directives: Modify the appearance or behavior of DOM elements
- Pipes: Transform data in templates
- Location Services: Interact with the browser URL
- HTTP Client: Make HTTP requests (in
@angular/common/http)
Key Features
Directives
The Common package provides essential directives for template manipulation:Structural Directives
Control DOM structure with
ngIf, ngFor, and ngSwitchAttribute Directives
Modify elements with
ngClass and ngStyleDeprecation Notice: As of Angular v20, structural directives like
ngIf, ngFor, and ngSwitch are deprecated in favor of the new control flow syntax (@if, @for, @switch blocks). They will be removed in v22.Pipes
Transform and format data in your templates:- Date Formatting:
DatePipefor date/time display - Number Formatting:
DecimalPipe,PercentPipe,CurrencyPipe - Async Handling:
AsyncPipefor observables and promises - Data Transformation:
JsonPipe,SlicePipe,KeyValuePipe - Text Transformation:
UpperCasePipe,LowerCasePipe,TitleCasePipe
Module Import
Many common directives and pipes are available throughCommonModule:
For standalone components, you can import individual directives and pipes instead of the entire
CommonModule.Standalone Usage
With Angular’s standalone components, you can import specific directives and pipes:Migration to Modern Syntax
Angular v17+ introduces built-in control flow that replaces structural directives:Related Pages
Directives
Learn about built-in directives
Pipes
Explore data transformation pipes
