What is @angular/common?
The @angular/common package is a core Angular library that provides commonly needed services, pipes, and directives that are essential for application development. It is part of the Angular framework and is used for tasks such as HTTP communication, localization, and various utility functions.
What are @angular/common's main functionalities?
HTTP Client
Provides a simplified API for HTTP functionality which allows performing HTTP requests and handling responses within an Angular application.
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
HttpClientModule
]
})
export class AppModule { }
Common Directives
Includes directives like ngIf, ngFor, and ngSwitch which are essential for controlling the rendering of the template.
import { CommonModule } from '@angular/common';
@NgModule({
imports: [
CommonModule
]
})
export class SharedModule { }
Location Services
Provides services for interacting with the browser's URL. Useful for routing and navigation within an Angular application.
import { Location } from '@angular/common';
@Component({
selector: 'app-component',
template: '<p>Current path: {{ location.path() }}</p>'
})
export class AppComponent {
constructor(public location: Location) { }
}
Date, Currency, and Decimal Pipes
Provides built-in pipes for formatting data such as dates, currency, and numbers.
import { DatePipe, CurrencyPipe, DecimalPipe } from '@angular/common';
@Component({
selector: 'app-component',
template: '<p>Today is {{ today | date }}</p><p>Amount: {{ amount | currency }}</p>'
})
export class AppComponent {
today = new Date();
amount = 1234.56;
}
Other packages similar to @angular/common
react
React is a JavaScript library for building user interfaces. While it is not a one-to-one comparison with @angular/common, React provides a component-based architecture similar to Angular's directives and services.
vue
Vue.js is a progressive JavaScript framework used for building UIs and single-page applications. It offers similar directives and reactivity systems but is generally considered to be more lightweight and easier to integrate into projects than Angular.
axios
Axios is a promise-based HTTP client for the browser and Node.js. It provides many of the same HTTP client capabilities as the HttpClientModule in @angular/common.
moment
Moment.js is a library for parsing, validating, manipulating, and formatting dates. It is similar to the DatePipe in @angular/common but is a standalone library focused solely on date manipulation.
19.0.0-next.1 (2024-08-22)
Breaking Changes
core
- The
autoDetect
feature of ComponentFixture
will now
attach the fixture to the ApplicationRef
. As a result, errors during
automatic change detection of the fixture be reported to the ErrorHandler
.
This change may cause custom error handlers to observe new failures that were previously unreported.
compiler-cli
| Commit | Type | Description |
| -- | -- | -- |
| 9e87593055 | feat | ensure template style elements are preprocessed as inline styles (#57429) |
core
| Commit | Type | Description |
| -- | -- | -- |
| b063468027 | feat | support TypeScript 5.6 (#57424) |
| 3b0dca75d6 | fix | Allow zoneless scheduler to run inside fakeAsync
(#56932) |
| f03d274e87 | fix | ComponentFixture autoDetect feature works like production (#55228) |
| d4449fce21 | fix | handle hydration of components that project content conditionally (#57383) |
migrations
| Commit | Type | Description |
| -- | -- | -- |
| 4ae66f25d0 | fix | account for members with doc strings and no modifiers (#57389) |
| ac93839d69 | fix | avoid migrating route component in tests (#57317) |
| 58a79b6e43 | fix | preserve type when using inject decorator (#57389) |
<!-- CHANGELOG SPLIT MARKER -->
<a name="19.0.0-next.0"></a>