Registry / storage / angular-2-local-storage

angular-2-local-storage

JSON →
library3.0.2jsnpmunverified

angular-2-local-storage v3.0.2 provides a LocalStorageService for Angular 2+ with a familiar API derived from angular-local-storage. It is AoT compatible, offers observables (errors$, removeItems$, setItems$, warning$) for reactive monitoring, and supports configurable prefix and storage type. Unlike its predecessor, it drops $rootScope events and the bind function (stubbed). The package ships TypeScript types and has peer dependencies on Angular (>=6.0) and RxJS (>=6.0). It is actively maintained on GitHub by phenomnomnominal.

npm install angular-2-local-storage
INSTALL
IMPORT
SIG · ANGULAR-2-LOCAL-ST
A
angular-2-local-storage
storagejavascriptv3.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LocalStorageService
import { LocalStorageService } from 'angular-2-local-storage'
import { LocalStorageService } from 'angular-2-local-storage/src'
The correct import is from the package root.
LocalStorageModule
import { LocalStorageModule } from 'angular-2-local-storage'
import { LocalStorageModule } from 'angular-2-local-storage' (no wrong pattern, but ensure Angular module is imported in NgModule)
Use NgModule imports: [LocalStorageModule.forRoot({...})]
ILocalStorageServiceConfig
import { ILocalStorageServiceConfig } from 'angular-2-local-storage'
import { ILocalStorageServiceConfig } from 'angular-2-local-storage/dist'
The interface is exported from the main package.

Shows injection of LocalStorageService, setting and getting a value from localStorage.

import { Component } from '@angular/core'; import { LocalStorageService } from 'angular-2-local-storage'; @Component({ selector: 'app-root', template: '<div>{{ value }}</div>' }) export class AppComponent { value: string; constructor(private localStorageService: LocalStorageService) { this.localStorageService.set('test', 'Hello World'); this.value = this.localStorageService.get('test') as string; } }
Debug
Known issues
breakingThe 'bind' function has been removed (stubbed to do nothing).
fix
Use observables (errors$, removeItems$, setItems$) instead of bind.
affects: >=3.0.0
deprecatedUsage with Angular <6.0 is not supported.
fix
Update to Angular 6+.
affects: >=3.0.0
gotchaThe storage prefix and storageType configuration must be passed via LocalStorageModule.forRoot(). If not configured, defaults are used: prefix = '' and storageType = 'localStorage'.
fix
Configure as shown in the README: LocalStorageModule.forRoot({ prefix: 'my-app', storageType: 'localStorage' }).
affects: >=3.0.0
Errors
Common errors & fixes
Error: Can't resolve 'angular-2-local-storage'
The package is not installed or is missing from node_modules.
fix
Run: npm install angular-2-local-storage
TypeError: this._localStorageService.set is not a function
The LocalStorageService is not properly injected or the method name is misspelled.
fix
Ensure the service is injected via constructor and use correct method names: set, get, remove, clear.
Upgrade
Version history
3.0.2latest on npm
Audit
Dependencies
@angular/corerequiredRequired to use Angular decorators and DI
@angular/commonrequiredProvides Angular common utilities (e.g., PlatformLocation)
@angular/platform-browserrequiredNeeded for browser-specific services like localStorage
rxjsrequiredProvides Observables for errors$, removeItems$, etc.
Agent activity
39 hits · last 30 days
node
32
Resources
angular-2-local-storage — npm install angular-2-local-storage · libregistry