iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
BEFORE_APP_SERIALIZED is an injection token from Angular’s @angular/platform-server package. It lets you register callbacks that run just before Angular serializes server-rendered platform state to a string. A callback may finish immediately or return a promise, so it can represent synchronous or asynchronous work that must complete before serialization.
What the token does
Angular documents BEFORE_APP_SERIALIZED as a stable API for functions executed by renderApplication or renderModule immediately before the current platform state is rendered to a string. Its declared type is InjectionToken<readonly (() => void | Promise<void>)[]>. In practical terms, the token is a place to provide one or more pre-serialization callbacks.
The timing is the important part: this hook is for work that needs to happen at the end of server rendering, before serialization. It is not a general-purpose hook for every stage of an Angular app’s lifecycle.
How to provide a callback
Angular’s integration example uses a multi provider, allowing callback functions to be registered with the token. A synchronous callback can return nothing; an asynchronous callback can return a promise.
#1 Best Overall
{ provide: BEFORE_APP_SERIALIZED, useValue: () => { /* synchronous work */ }, multi: true }
{ provide: BEFORE_APP_SERIALIZED, useValue: async () => { /* asynchronous work */ }, multi: true }
This illustrates the provider shape, not a recommendation to use the hook for any particular task. Adapt the provider syntax to the server-rendering setup and Angular version in your application.
When to use it
Use this hook only when a task must complete immediately before the server-rendered platform state is serialized. Choose a synchronous callback when the work is immediate, or return a promise when the work is asynchronous and needs to be represented as part of the callback.
Rank #2
If the work belongs at another point in application startup or rendering, this token may not be the right lifecycle mechanism. The API reference establishes the callback timing and return types, but does not prescribe production use cases.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Check behavior for your Angular version
The official API reference documents the token, and Angular’s source integration test demonstrates multi-provider registration, including a promise-based callback. For version-specific behavior or migration questions, consult the documentation and package declarations for the Angular version you have installed; repository examples on the mutable main branch may not match every release.
Quick Recap
Rank #4
Rank #3
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

