Skip to main content

Overview

The @angular/platform-browser package provides the infrastructure for running Angular applications in a web browser. It includes bootstrapping APIs, DOM manipulation services, and security utilities for browser-based applications.

Bootstrap Functions

bootstrapApplication

Bootstraps a standalone component as the root of an Angular application.
Type<unknown>
required
A standalone component to render as the application root.
ApplicationConfig
Configuration object containing providers and other application settings.
BootstrapContext
Optional context providing a pre-existing platform injector (useful for server-side rendering).
Returns: Promise<ApplicationRef> - The bootstrapped application reference. Example:
The root component must be a standalone component. Use standalone: true in the component decorator.

createApplication

Creates an Angular application without bootstrapping any components. Components can be bootstrapped later using the returned ApplicationRef.
ApplicationConfig
Configuration object containing providers and other application settings.
BootstrapContext
Optional context providing a pre-existing platform injector.
Returns: Promise<ApplicationRef> - Application reference for manual component bootstrapping. Example:

platformBrowser

Creates a browser platform instance. This is typically used for advanced scenarios where you need explicit control over platform creation.
StaticProvider[]
Optional additional platform-level providers.
Returns: PlatformRef - Browser platform reference. Example:

Modules

BrowserModule

Exports required infrastructure for all Angular apps running in a browser. Includes CommonModule and ApplicationModule.
Example:
BrowserModule should only be imported once in your root module. Child modules should import CommonModule instead.

Services

Title

Service for getting and setting the HTML document title.
Methods:
() => string
Returns the current document title.
(newTitle: string) => void
Sets the document title.
Example:

Meta

Service for managing HTML <meta> tags. Essential for SEO, social sharing, and security configurations.
MetaDefinition Type:
Methods:
(tag: MetaDefinition, forceCreation?: boolean) => HTMLMetaElement | null
Adds a meta tag to the document. If forceCreation is false (default), returns existing tag if found.
(tags: MetaDefinition[], forceCreation?: boolean) => HTMLMetaElement[]
Adds multiple meta tags to the document.
(attrSelector: string) => HTMLMetaElement | null
Retrieves a meta tag using an attribute selector (e.g., "name='description'").
(attrSelector: string) => HTMLMetaElement[]
Retrieves all meta tags matching the attribute selector.
(tag: MetaDefinition, selector?: string) => HTMLMetaElement | null
Updates an existing meta tag or creates one if it doesn’t exist.
(attrSelector: string) => void
Removes a meta tag matching the attribute selector.
Example:

DomSanitizer

Service for sanitizing values to prevent Cross-Site Scripting (XSS) attacks. Provides methods to sanitize or bypass sanitization for trusted content.
Security Contexts:
  • SecurityContext.HTML - HTML content
  • SecurityContext.STYLE - CSS styles
  • SecurityContext.SCRIPT - JavaScript code
  • SecurityContext.URL - URLs in hyperlinks or images
  • SecurityContext.RESOURCE_URL - URLs for loading executable code
Methods:
(context: SecurityContext, value: SafeValue | string | null) => string | null
Sanitizes a value for use in the specified security context.
(value: string) => SafeHtml
Marks HTML as trusted. WARNING: Only use with trusted content to avoid XSS vulnerabilities.
(value: string) => SafeStyle
Marks CSS as trusted. WARNING: Only use with trusted content.
(value: string) => SafeScript
Marks JavaScript as trusted. WARNING: Only use with trusted content.
(value: string) => SafeUrl
Marks a URL as trusted. WARNING: Only use with trusted URLs.
(value: string) => SafeResourceUrl
Marks a resource URL as trusted. WARNING: Only use with trusted resource URLs.
Example:
Only bypass sanitization for content you completely trust. Never bypass sanitization for user-generated content or data from external sources. This can expose your application to XSS attacks.
Sanitizing URLs:

Hydration

provideClientHydration

Configures client-side hydration for applications using server-side rendering (SSR). Hydration improves initial load performance by reusing server-rendered DOM.
HydrationFeature[]
Optional hydration features to enable (event replay, i18n support, etc.).
Available Features:
  • withEventReplay() - Replays user events that occurred before hydration completed
  • withI18nSupport() - Enables hydration for internationalized content
  • withNoHttpTransferCache() - Disables HTTP response caching between server and client
  • withHttpTransferCacheOptions(options) - Configures HTTP transfer cache
  • withIncrementalHydration() - Enables incremental hydration for better performance
Example:
Client-side hydration requires server-side rendering to be configured. See @angular/platform-server for SSR setup.

Utilities

provideProtractorTestingSupport

Provides testability support for applications using Protractor or other testing tools that rely on Angular’s testability APIs.
Example:

By

Utility class for creating platform-agnostic DOM selectors in tests.
Example:

@angular/platform-server

Server-side rendering APIs

@angular/core

Core Angular APIs

Router

Application routing

HttpClient

HTTP communication