What is @angular/platform-browser?
The @angular/platform-browser package provides services that are essential for running Angular applications in a web browser. This includes DOM manipulation, rendering, and browser interaction APIs.
What are @angular/platform-browser's main functionalities?
DOM Manipulation
The BrowserModule provides services that are necessary for any web app, such as DOM rendering, sanitization, and location. It should be imported once in the root module of the app.
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
imports: [BrowserModule],
...
})
export class AppModule { }
Browser Event Handling
The package allows components to handle browser events such as resize, keyup, and more through the HostListener decorator.
import { Component, HostListener } from '@angular/core';
@Component({...})
export class MyComponent {
@HostListener('window:resize', ['$event'])
onResize(event) {
// Handle the browser resize event
}
}
Safe Interpolation
The DomSanitizer service helps prevent Cross Site Scripting Security bugs (XSS) by sanitizing values to be safe to use in the different DOM contexts.
import { DomSanitizer } from '@angular/platform-browser';
@Component({...})
export class MyComponent {
safeUrl;
constructor(private sanitizer: DomSanitizer) {
this.safeUrl = this.sanitizer.bypassSecurityTrustResourceUrl('https://example.com');
}
}
Other packages similar to @angular/platform-browser
react-dom
Similar to @angular/platform-browser for Angular, react-dom is used with React to interact with the DOM. It provides methods for rendering components into the DOM and working with the DOM elements.
vue
Vue is a progressive framework for building user interfaces. It provides its own methods for DOM manipulation and updates, similar to what @angular/platform-browser does for Angular applications.
preact
Preact is a fast 3kB alternative to React with the same modern API. It provides similar functionalities for rendering and handling the DOM as @angular/platform-browser does for Angular.
19.1.0-next.1 (2024-12-04)
compiler-cli
| Commit | Type | Description |
| -- | -- | -- |
| f280467398 | fix | account for multiple generated namespace imports in HMR (#58924) |
core
| Commit | Type | Description |
| -- | -- | -- |
| e894a5daea | feat | set kind field on template and effect nodes (#58865) |
| 3b765367f3 | fix | Explicitly manage TracingSnapshot lifecycle and dispose of it once it's been used. (#58929) |
migrations
| Commit | Type | Description |
| -- | -- | -- |
| e31e52e177 | fix | class content being deleted in some edge cases (#58959) |
| 508d3a1b3b | fix | correctly strip away parameters surrounded by comments in inject migration (#58959) |
| 7191aa6e09 | fix | don't migrate classes with parameters that can't be injected (#58959) |
| a4924af6d5 | fix | inject migration aggressively removing imports (#58959) |
| 35165d152d | fix | inject migration dropping code if everything except super is removed (#58959) |
| 68e5ba7a3a | fix | preserve type literals and tuples in inject migrations (#58959) |
platform-server
| Commit | Type | Description |
| -- | -- | -- |
| 1cfbfc66d3 | fix | remove peer dependency on animations (#58997) |
<!-- CHANGELOG SPLIT MARKER -->
<a name="19.0.2"></a>