Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BaseStorage

BaseStorage is where all the implementation of the storage system resides. This can be used to make custom storage objects if needed but more than likely, LocalStorage and SessionStorage will handle everything you need and creating services around those will be easier than creating a new storage object. But for those situations where something else is needed, this is the class for you.

NOTE: BaseStorage is an abstract class but the documentation generator makes no distintion.

Hierarchy

Implements

  • OnDestroy
  • Storage

Indexable

[key: string]: any

Gets or set a value from storage. Unlike getItem and setItem, the value is not required to be a string. All values will be serialized to string prior to being stored. To specify serialization, {@link StorageOptions#transformer}

NOTE: BaseStorage is an abstract class but the documentation generator makes no distintion.

Index

Constructors

constructor

  • Initializes the storage system by attaching to the angular2 change detection system and the Storage event system. Then syncronizes the object with data from storage while respecting the options set. LocalStorage

    Parameters

    • ngZone: NgZone

      The Zone handling angular 2 change detection.

    • storage: Storage

      An object that implements the Storage interface. Generally localStorage or sessionStorage

    • transformer: JSON

      An object that implements the JSON interface. This is injected using the SERDES_OBJECT

    • Optional options: StorageOptions

      Contains the options that will be used with the instance

    Returns BaseStorage

Accessors

length

  • get length(): number
  • The number of values this instance is managing

    Returns number

Methods

clear

  • clear(): void
  • Removes all keys managed by the storage object.

    Returns void

getItem

  • getItem(key: string): string
  • Retrieves data stored is storage.

    Parameters

    • key: string

      The identifier used to locate data in storage.

    Returns string

Protected getProperty

  • getProperty<T>(name: string): T
  • Retrieves data from the object stored as a property.

    Type parameters

    • T

    Parameters

    • name: string

    Returns T

key

  • key(index: number): string
  • Retrieves an identifier

    Parameters

    • index: number

      The position at which to look for an identifier. Index be at least zero and must be less than length.

    Returns string

ngOnDestroy

  • ngOnDestroy(): void

removeItem

  • removeItem(key: string): void
  • Deletes data stored in storage

    Parameters

    • key: string

      The identifier used to locate the data to be deleted

    Returns void

setItem

  • setItem(key: string, value: string): void
  • Stores data in storage

    Parameters

    • key: string

      The identifier to associate stored data with

    • value: string

      The data to place in storage

    Returns void

Protected setProperty

  • setProperty(name: string, value: any): void
  • Stores data in a private private property that will not be stored in storage. This is necessary because creating a class property results in an extra key in storage.

    Parameters

    • name: string
    • value: any

    Returns void

Generated using TypeDoc