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.7 (2024-09-25)
Breaking Changes
core
-
Changes to effect timing which generally has two implications:
-
effects which are triggered outside of change detection run as part of
the change detection process instead of as a microtask. Depending on the
specifics of application/test setup, this can result in them executing
earlier or later (or requiring additional test steps to trigger; see below
examples).
-
effects which are triggered during change detection (e.g. by input
signals) run earlier, before the component's template.
We've seen a few common failure cases:
-
Tests which used to rely on the Promise
timing of effects now need to
await whenStable()
or call .detectChanges()
in order for effects to
run.
-
Tests which use faked clocks may need to fast-forward/flush the clock to
cause effects to run.
-
effect()
s triggered during CD could rely on the application being fully
rendered (for example, they could easily read computed styles, etc). With
the change, they run before the component's updates and can get incorrect
answers. The recent afterRenderEffect()
API is a natural replacement for
this style of effect.
-
effect()
s which synchronize with the forms system are particularly
timing-sensitive and might need to adjust their initialization timing.
-
ExperimentalPendingTasks
has been renamed to
PendingTasks
.
core
| Commit | Type | Description |
| -- | -- | -- |
| fc59e2a7b7 | feat | change effect() execution timing & no-op allowSignalWrites
(#57874) |
| a7eff3ffaa | feat | mark signal-based query APIs as stable (#57921) |
| a1f229850a | feat | migrate ExperimentalPendingTasks to PendingTasks (#57533) |
| 950a5540f1 | fix | Ensure the ViewContext
is retained after closure minification (#57903) |
language-service
| Commit | Type | Description |
| -- | -- | -- |
| 7ecfd89592 | fix | The suppress diagnostics option should work for external templates (#57873) |
<!-- CHANGELOG SPLIT MARKER -->
<a name="18.2.6"></a>