0.0.8 • Published 5 years ago

cdl-localstorage v0.0.8

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

Localstorage

This is a simple local storage which is developed using javascript.

Installation instruction

npm install cdl-localstorage --save

Instruction to use the package

How to use?

Please follow below instruction to implement local storage in your angular application.

//in module
import { LocalstorageModule } from 'cdl-localstorage'; 

imports: [
    LocalstorageModule
]

// In your component ts file

import { LocalstorageService } from 'cdl-localstorage';

First way to utilize service

// Extend service to utilize its functions

export class AppComponent extends LocalstorageService {

    constructor() {
        super();
    }

    ngOnInit() {
        //Set value in local storage by key value pair
        this.setValue(key, value);

        //Get value from local storage by key
        this.getValue(key);

        //Clear specific value in local storage by key
        this.clearValue(key);

        //Clear entire local storage
        this.clearAll();
    }
}

Second way to utilize service

// Initilize service to constructor

export class AppComponent {

    constructor(private localstorageService: LocalstorageService) {
        //TODO:
    }

    ngOnInit() {
        //Set value in local storage by key value pair
        this.localstorageService.setValue(key, value);

        //Get value from local storage by key
        this.localstorageService.getValue(key);
        
        //Clear specific value in local storage by key
        this.localstorageService.clearValue(key);
        
        //Clear entire local storage
        this.localstorageService.clearAll();
    }
}