phenomnomnominal / angular-2-local-storage

LocalStorageService for Angular 2 with the same API as angular-local-storage
MIT License
93 stars 49 forks source link

angular-2-local-storage

LocalStorageService for Angular with mostly the same API (and most of the code) from angular-local-storage.

AoT compatible.

Differences

Install

npm install angular-2-local-storage

Usage

You can optionally configure the module:

import { LocalStorageModule } from 'angular-2-local-storage';

@NgModule({
    imports: [
        LocalStorageModule.forRoot({
            prefix: 'my-app',
            storageType: 'localStorage'
        })
    ],
    declarations: [
        ..
    ],
    providers: [
        ..
    ],
    bootstrap: [AppComponent]
})
export class AppModule { }

Then you can use it in a component:

import { LocalStorageService } from 'angular-2-local-storage';

@Component({
    // ...
})
export class SomeComponent {
    constructor (
        private _localStorageService: LocalStorageService
    ) {
        // YAY!
    }
}

Configuration options

import { ILocalStorageServiceConfig } from 'angular-2-local-storage'; for type information about the configuration object.