[ Web Proxy ]
URL:
Viewing: https://angular.dev/api/core/TransferState [Back]  [Original]

TransferState Angular Skip to main content
menu
close
more_horiz
menuAPI
@angular/core

TransferState

Class
stable

A key value store that is transferred from the application on the server side to the application on the client side.

On this page

    arrow_upward_alt Back to the top

    API

        
          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>): boolean;  readonly isEmpty: boolean;  onSerialize<T>(key: StateKey<T>, callback: () => T): void;  toJson(): string;}
        
        

    get

    T

    Get the value corresponding to a key. Return defaultValue if key is not found.

    @paramkeyStateKey<T>
    @paramdefaultValueT
    @returnsT

    set

    void

    Set the value corresponding to a key.

    @paramkeyStateKey<T>
    @paramvalueT
    @returnsvoid

    remove

    void

    Remove a key from the store.

    @paramkeyStateKey<T>
    @returnsvoid

    hasKey

    boolean

    Test whether a key exists in the store.

    @paramkeyStateKey<T>
    @returnsboolean

    isEmpty

    boolean

    Indicates whether the state is empty.

    onSerialize

    void

    Register a callback to provide the value for a key when toJson is called.

    @paramkeyStateKey<T>
    @paramcallback() => T
    @returnsvoid

    toJson

    string

    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.

    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.

    Jump to details

    Web Proxy Viewer  |  New URL  |  Original Page