TransferState • Angular
Get the value corresponding to a key. Return defaultValue if key is not found.
@returnsT
Set the value corresponding to a key.
@returnsvoid
Remove a key from the store.
@returnsvoid
Test whether a key exists in the store.
@returnsboolean
Indicates whether the state is empty.
Register a callback to provide the value for a key when toJson is called.
@returnsvoid
Serialize the current state of the store to JSON.
@returnsstring
Description
A key value store that is transferred from the application on the server side to the application on the client side.
The TransferState is available as an injectable token.
On the client, just inject this token using DI and use it, it will be lazily initialized.
On the server it's already included if renderApplication function is used. Otherwise, import
the ServerTransferStateModule module to make the TransferState available.
The values in the store are serialized/deserialized using JSON.stringify/JSON.parse. So only boolean, number, string, null and non-class objects will be serialized and deserialized in a non-lossy manner.