@neoprospecta/angular-local-database

4.0.0 • Public • Published

Angular Local DataBase for Angular 2+

A service to store content and information into browser's localStorage and/or sessionStorage

How to install:

Have two ways to install angular-local-database inside your project:

  • First way:

    1. Install dependence directly from NPM, running this command on terminal in the project' root folder.

      npm install @neoprospecta/angular-local-database --save

  • Second way:

    1. Declare angular-local-database as dependence into package.json file.

      "@neoprospecta/angular-local-database":"^4.0.0"

    2. Install dependence, running this command on terminal in the project's root folder.

      npm install

How to use:

  • Import LocalDataBaseModule in the project's root module.
import { LocalDataBaseModule } from '@neoprospecta/angular-local-database';

@NgModule({
    ...
  imports: [
    LocalDataBaseModule
  ],
    ...
})
export class AppModule { }
  • Import LocalDataBaseService in project's component that needs to use.
import { LocalDataBaseService } from '@neoprospecta/angular-local-database';

@Component(...)
export class AppComponent {
    ...
  constructor(
    private localDataBaseService: LocalDataBaseService
  ){ }
  ...
}
  • Done, now can use a function from LocalDataBaseService. For example:
this.localDataBaseService.set('key', 'value');

Features

Set data into LocalStorage or SessionStorage

  • Persist into LocalStorage and SessionStorage
/* First way: Omittng 3th parameter */
this.localDataBaseService.set('key', 'value');
/* Second way: Passing 3th parameter */
this.localDataBaseService.set('key', 'value', true);
  • Persist only into SessionStorage. (In this way when the user closes the browser the memory is cleaned).
this.localDataBaseService.set('key', 'value', false);

Get data from SessionStorage or LocalStorage

  • Try to return data from SessionStorage, if hasn't, try to return from LocalStorage, if hasn't return undefined.
this.localDataBaseService.get('key');

Remove data from SessionStorage and/or LocalStorage

  • Try to remove in both SessionStorage and LocalStorage.
this.localDataBaseService.remove('key');

Features Table

Feature Function
set (key: string, value: any, persist: boolean = true): boolean
get (key: string): void
remove (key: string): boolean

License

© Neoprospecta | MIT LICENSE

N|Solid

Package Sidebar

Install

npm i @neoprospecta/angular-local-database

Weekly Downloads

1

Version

4.0.0

License

MIT

Last publish

Collaborators

  • netorutes
  • neopctdeploy
  • lfelipedeoliveira
  • renataoliveira
  • vinagreti
  • neopct