@neoprospecta/angular-local-database
v4.0.0
Published
Angular local database
Downloads
2
Readme
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:
Install dependence directly from NPM, running this command on terminal in the project' root folder.
npm install @neoprospecta/angular-local-database --save
Second way:
Declare angular-local-database as dependence into package.json file.
"@neoprospecta/angular-local-database":"^4.0.0"
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