Registry / storage / angular-local-storage

angular-local-storage

JSON →
library0.7.1jsnpmunverified

An AngularJS module that provides a service to access the browser's local storage and session storage with a consistent API, fallback to cookies when storage is not supported, and support for prefixes to avoid key collisions. Version 0.7.1 is the latest stable release; the package is in maintenance mode with no active development. Key differentiators: integrates directly with AngularJS (1.x), provides cookie fallback, supports prefix and storage type configuration via provider. Not suitable for modern Angular (2+).

npm install angular-local-storage
INSTALL
IMPORT
SIG · ANGULAR-LOCAL-STOR
A
angular-local-storage
storagejavascriptv0.7.1
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
angular.module('myApp', ['LocalStorageModule']).controller('Ctrl', function(localStorageService) { ... })
import { localStorageService } from 'angular-local-storage'
AngularJS module; inject the service into controllers/services, not imported as ES module.
localStorageServiceProvider
angular.module('myApp').config(function(localStorageServiceProvider) { ... })
import { localStorageServiceProvider } from 'angular-local-storage'
Used in config block to set prefix, storage type, etc. Not directly imported.
LocalStorageModule
angular.module('myApp', ['LocalStorageModule'])
var app = angular.module('myApp'); app.requires.push('LocalStorageModule');
Module name string, not a variable. Must be passed as dependency when defining the app module.

Basic usage of localStorageService in an AngularJS controller: set, get, remove, clearAll.

// Include angular and angular-local-storage script tags // Then define your app: var myApp = angular.module('myApp', ['LocalStorageModule']); myApp.controller('MyController', function($scope, localStorageService) { // Set an item localStorageService.set('myKey', 'myValue'); // Get an item var value = localStorageService.get('myKey'); // Remove an item localStorageService.remove('myKey'); // Clear all (only items with the prefix) localStorageService.clearAll(); });
Debug
Known issues
deprecatedThis library is designed for AngularJS (1.x) only. It does not work with Angular 2+.
fix
Use a modern local storage wrapper like @ngx-pwa/local-storage or native localStorage with Angular services.
affects: >=0.0.0
gotchaIf setDefaultToCookie(true) and localStorage is unsupported, data is stored in cookies. Cookies have a size limit (~4KB) and are sent with every HTTP request, potentially causing performance issues.
fix
Disable cookie fallback by setting setDefaultToCookie(false) if you don't need it, or ensure storage is supported.
affects: >=0.0.0
gotchaThe set() method only accepts string keys; non-string keys are converted to string via toString(). This can cause unexpected key collisions.
fix
Always use string keys explicitly.
affects: >=0.0.0
gotchaThe service stores data as JSON strings. Objects and arrays are serialized/deserialized automatically, but special objects (e.g., Date) may lose type information.
fix
Use JSON-safe values or implement custom serialization.
affects: >=0.0.0
Errors
Common errors & fixes
Error: [$injector:unpr] Unknown provider: localStorageServiceProviderProvider <- localStorageServiceProvider
Missing module dependency or script not loaded before Angular.
fix
Ensure 'LocalStorageModule' is added to your app's dependency list and the angular-local-storage script is loaded after angular.js.
TypeError: Cannot read property 'set' of undefined
localStorageService not injected correctly into controller.
fix
Inject 'localStorageService' as a dependency in your controller function: function($scope, localStorageService) { ... }
ReferenceError: localStorageServiceProvider is not defined
Trying to use localStorageServiceProvider outside of a config block.
fix
Use localStorageServiceProvider only inside angular.module('myApp').config(function(localStorageServiceProvider) { ... });
Upgrade
Version history
0.7.1latest on npm
Audit
Dependencies
angularrequiredpeer dependency; requires AngularJS 1.x to be loaded
Agent activity
43 hits · last 30 days
node
38
Resources
angular-local-storage — npm install angular-local-storage · libregistry