Package Exports
- angular-2-local-storage
- angular-2-local-storage/dist/index
- angular-2-local-storage/dist/local-storage.module
- angular-2-local-storage/dist/local-storage.service
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (angular-2-local-storage) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
angular-2-local-storage
LocalStorageService for Angular 2 with mostly the same API (and most of the code) from angular-local-storage.
AoT compatible.
Differences:
- No events broadcast on $rootScope - LocalStorageService exposes observables for
errors$,removeItems$,setItems$andwarning$if you really need something to happen when something happens. - The
bindfunction doesn't work anymore (there is a stub so this can still be a drop-in, but it'll do nothing).
Install:
npm install angular-2-local-storage
Usage:
With angular-cli or vanilla WebPack:
With the latest angular-cli (WebPack), no config is required.
For older versions (SystemJS based) see the comments here for configuration: Issue #20
With TypeScript
Nothing to configure, the typings are included in the package.
In your app:
First you need to configure the service:
import { LocalStorageModule } from 'angular-2-local-storage';
@NgModule({
imports: [
LocalStorageModule.withConfig({
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.