class final
A key value store that is transferred from the application on the server side to the application on the client side.
class TransferState {
isEmpty: boolean
get<T>(key: StateKey<T>, defaultValue: T): T
set<T>(key: StateKey<T>, value: T): void
remove<T>(key: StateKey<T>): void
hasKey<T>(key: StateKey<T>): boolean
onSerialize<T>(key: StateKey<T>, callback: () => T): void
toJson(): string
} 'root'
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.
| Property | Description |
|---|---|
isEmpty: boolean | Read-Only Indicates whether the state is empty. |
| get() |
|---|
| Get the value corresponding to a key. Return |
| set() |
|---|
| Set the value corresponding to a key. |
| remove() |
|---|
| Remove a key from the store. |
| hasKey() |
|---|
| Test whether a key exists in the store. |
| onSerialize() | ||||||
|---|---|---|---|---|---|---|
| Register a callback to provide the value for a key when | ||||||
|
key | StateKey<T> | |
callback | () => T |
void
| toJson() |
|---|
| Serialize the current state of the store to JSON. |
|
© 2010–2023 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/core/TransferState