TransferState
TransferState
class
A key value store that is transferred from the application on the server side to the application on the client side.
class TransferState {
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>)
onSerialize<T>(key: StateKey<T>, callback: () => T): void
toJson(): string
}
Provided in
-
BrowserTransferStateModule
../../platform-server/servertransferstatemodule
ServerTransferStateModule
Description
TransferState
will be available as an injectable token. To use it import ServerTransferStateModule
on the server and BrowserTransferStateModule
on the client.
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.
Methods
get() | ||||||
---|---|---|---|---|---|---|
Get the value corresponding to a key. Return defaultValue if key is not found.
| ||||||
get<T>(key: StateKey<T>, defaultValue: T): TParameters
Returns
|
set() | ||||||
---|---|---|---|---|---|---|
Set the value corresponding to a key. | ||||||
set<T>(key: StateKey<T>, value: T): voidParameters
Returns
|
remove() | |||
---|---|---|---|
Remove a key from the store. | |||
remove<T>(key: StateKey<T>): voidParameters
Returns
|
hasKey() | |||
---|---|---|---|
Test whether a key exists in the store. | |||
hasKey<T>(key: StateKey<T>)Parameters
|
onSerialize() | ||||||
---|---|---|---|---|---|---|
Register a callback to provide the value for a key when toJson is called.
| ||||||
onSerialize<T>(key: StateKey<T>, callback: () => T): voidParameters
Returns
|
toJson() |
---|
Serialize the current state of the store to JSON. |
toJson(): stringParametersThere are no parameters. Returns
|
© 2010–2021 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v11.angular.io/api/platform-browser/TransferState