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.0.0-next.4 (2024-09-09)
compiler
| Commit | Type | Description |
| -- | -- | -- |
| 40ff18f87a | fix | produce less noisy errors when parsing control flow (#57711) |
core
| Commit | Type | Description |
| -- | -- | -- |
| 6ea8e1e9aa | feat | Add a schematics to migrate to standalone: false
. (#57643) |
migrations
| Commit | Type | Description |
| -- | -- | -- |
| cbec46a51d | feat | migrate .pipe calls in outputs used in tests (#57691) |
| 68e5370a66 | feat | remove complete calls for migrated outputs (#57671) |
| 9da21f798d | feat | replace .next usage on outputs (#57654) |
| 71f5ef2aa5 | fix | change imports to be G3 compatible (#57654) |
| 3a264db866 | fix | properly handle comments in output migration (#57691) |
| fc95a9adff | fix | replace leftover modules with their exports during pruning (#57684) |
<!-- CHANGELOG SPLIT MARKER -->
<a name="19.0.0-next.3"></a>