grevory / angular-local-storage Goto Github PK
View Code? Open in Web Editor NEWAn AngularJS module that gives you access to the browsers local storage with cookie fallback
License: Other
An AngularJS module that gives you access to the browsers local storage with cookie fallback
License: Other
Once i installed this good feature, i found there is no compressed version(.min.js). Which means, if i want compile my project in production, i have to minify angular-local-storage.js myself.
Hi,
I am wondering why you chose to use angular.constant. I have a scenario where i have multiple angular apps on the same domain. I would like to reassign the prefix used to store keys individually for each one of the apps. Would you consider using value instead? I can submit a pull request.
Thanks.
Oooops.
Sorry - indeed the wrong repo.
My bad :)
Get this error when open my site on iPhone:
Error: 'undefined' is not an object (evaluating '$document.cookie.split')
If I try to get $document.cookie.split function locally โ get the same error too.
Fix this by removing '$' from '$document':
in line 280 and in line 300:
var cookies = document.cookie.split(';');
Don't know if this is best solution, but it works.
I used to pull this package in via Bower - but now a bower search can't find it. An attempt to install via 'bower install https://github.com/grevory/angular-local-storage' doesn't work either.
The documentation needs to reflect the latest version of Angular
I tried the sample app:
http://gregpike.net/demos/angular-local-storage/demo.html
the stored variable doesn't survive the page reload
Use lowerCamelCase
and no need of module
and service
. Whether it's a module or service and be inferred by context.
e.g.
angular.module('yourModule', ['localStorage'])
.controller('yourCtrl', [
'$scope',
'localStorage',
function($scope, localStorage) {
localStorage.clearAll();
localStorage.add('Favorite Sport','Ultimate Frisbee');
}]);
Hi,
Thanks for your project. Very useful.
You made the release 0.0.1, it's good. But you must also report the release number in the js files or how can I know, after download the files, witch release it is ?
bower extract angular-local-storage#~0.0.4 archive.tar.gz
bower mismatch Version declared in the json (0.0.3) is different than the resolved one (0.0.4)
It would be more fluent if you could add promises to the module.
Example:
localStorageService.get('foo').then(function() {resolve});
Just let me know if i can assist you somehow.
The demo @ http://gregpike.net/demos/angular-local-storage/demo/demo.html doesn't currently work.
I assume the functionality should be that on reload the data remains, but it is always blank when I reload the page.
Using this demo page: http://gregpike.net/demos/angular-local-storage/demo/demo.html
Im on Firefox 27.0.1 on OSX 10.8.4.
Firefox shows 2 warnings on the console:
01:16:29.745 Use of getUserData() or setUserData() is deprecated. Use WeakMap or element.dataset instead. requestNotifier.js:64
01:16:30.462 Use of attributes' specified attribute is deprecated. It always returns true. angular.min.js:39
I assume these are not real issues, so not immediate guesses on why its not working as I havent reviewed the code, only tried the demo.
I'm trying to save a value in a cookie. I'm not sure what angular-local-storage
is meant to do different from angular-cookie
.
I've tried to save the cookie with the following code:
localStorageService.clearAll();
localStorageService.set('test_1','test-value');
localStorageService.add('test_2', 'test-value');
localStorageService.cookie.add('test_3', 'test-value');
localStorageService.cookie.set('test_4', 'test-value');
None of the previous command are settings the cookie value. What am I missing?
Why should I use angular-local-storage
instead of angular-cookie
?
Cheers
Several days ago I was able to install version 0.0.2
using Bower. I'm no longer able to install that, or 0.0.1
. Looks like I can install using v0.1
though.
It seems you did an informal rollback in this commit: 0a51629#diff-0a08a7565aba4405282251491979bb6b
What's going on with the tagging for this project?
Hello, I'm wondering is there a particular reason for not using $window and $document knowing that it is only window and document object wrapped?
Cheerz!
Hi thanks your storage works very well, do you have idea of compatibility with the browsers?
Hi,
I'm not really sure about this, but looks like the module itself doesnt fallback to cookie storage when localStorage not available, does it ?
// If this browser does not support local storage use cookies
if (!browserSupportsLocalStorage()) {
$rootScope.$broadcast('LocalStorageModule.notification.warning','LOCAL_STORAGE_NOT_SUPPORTED');
return false;
}
looks like you just send a warning but its never catched ?
i'm a mistaken ? is it a work in progress ? do you need pull request ?
Thanks :)
browserSupportsLocalStorage always returns true if local storage is not supported when it should return false.
if the var supported is false the function never tries to set an item and returns true as the default. What should happen is that the function should return the value of supported instead of the hard coded value of true.
var browserSupportsLocalStorage = (function () {
try {
var supported = (storageType in $window && $window[storageType] !== null);
// When Safari (OS X or iOS) is in private browsing mode, it appears as though localStorage
// is available, but trying to call .setItem throws an exception.
//
// "QUOTA_EXCEEDED_ERR: DOM Exception 22: An attempt was made to add something to storage
// that exceeded the quota."
var key = prefix + '__' + Math.round(Math.random() * 1e7);
if (supported) {
webStorage.setItem(key, '');
webStorage.removeItem(key);
}
return supported;
} catch (e) {
storageType = 'cookie';
$rootScope.$broadcast('LocalStorageModule.notification.error', e.message);
return false;
}
}());
It might be cleaner if the cookie methods did not use the prefix internally but instead were passed 'prefix + key' when calling them from the local storage methods. That way the cookie methods exposed can be used for any cookie whilst calls to add to local storage use the prefix as appropriate.
Usage would then be symmetric:
getFromCookies(prefix + key);
localStorage.getItem(prefix + key);
I've been messing around with this module in a small project using node, express and angular and noticed that the isSupported function doesn't work.
In library function browserSupportsLocalStorage, should line
var supported = (storageType in $window && $window[storageType] !== null);
not read
var supported = ("localStorage" in $window) && ($window['localStorage'] !== null)
i.e. referencing item 'localStorage' and not 'storageType'
I see in code that storageType should be defaulting to 'localStorage' so above should work - I'm not sure what's up.
If localstorage and cookies turned off in chrome, it throws exception in 71line:
var webStorage = $window[storageType];
I wrapped this in try-catch block for my project. Maybe you can add too? Or maybe there are more clean solution..
Hi, just fixed a bug in the function browserSupportsLocalStorage around line 99. Below is a snippet of code. Sorry, I didn't have time to create a pull-request, but thought someone might find the fix useful too.
if (supported) {
webStorage.setItem(key, '');
webStorage.removeItem(key);
}
return supported;
In your code you return True, but it should return the value in the variable "supported" instead, as per above.
Should the options be set in a provider instead of constants and values so they can be modified in an apps .config() ?
Consider wrapping sessionStorage/localStorage accessors with the following IE8-friendly check:
if ( webStorage.begin ) {
webStorage.begin();
}
// Local or session storage operation
if ( webStorage.commit ) {
webStorage.commit();
}
Running jshint I get
[L52:C38] W116: Expected '{' and instead saw 'value'.
if (typeof value == "undefined") value = null;
[L78:C16] W116: Expected '{' and instead saw 'return'.
if (!item) return null;
[L123:C46] W033: Missing semicolon.
keys.push(key.substr(prefixLength))
[L176:C38] W116: Expected '{' and instead saw 'return'.
if (typeof value == "undefined") return false;
Warning: Task "jshint:src" failed. Used --force, continuing.
I'm not an angularjs guru. Trying to use ALS with angular-translate where in app.config() I can specify my own localstorage service for storing current language infowith:
$translateProvider.useStorage('localStorageService');
I am getting error, that my localstorageservice does not provice set() and get() methods.
Maybe this is related to the "service" nature of angular-storage-service ?
http://stackoverflow.com/questions/15666048/angular-js-service-vs-provide-vs-factory
Thanks
It seems that currently the storage type is configured once for the module. But what if an application would like to use both local and session storage? One nice approach may be to have two services exposed from the module: one "localStorageService" and one "sessionStorageService", and either or both may be injected as needed.
Hi,
the version in bower is outdated (changes from the last commit are missing).
Please update :)
best,
MM.
addToCookies in the minified version does not work. The non minified version does work. I did not try to debug it other than to switch out js files.
Warren
Could you please make it available for .NET developers in a form of a NuGet package?
Examples:
https://www.nuget.org/packages/Moment.js
https://www.nuget.org/packages/underscore.js
Thank you!
bower ENORESTARGET No tag found that was able to satisfy on bower install ~0.0.2
i'm getting this error when trying to install using bower.
As cookies, it would be nice create expiration date for an item.
example
http://nekman.se/encryptedlocalstorage-with-angularjs/
Crypto js Angular
https://github.com/SimplyDo/cryptography
es posible?
It might by interesting to add support for QUOTA_EXCEEDED_ERR? http://diveintohtml5.info/storage.html
Add usage instructions
Due to change cf39b3c angularLocalStorage
is no longer global. How can I now set the prefix
constant?
I want to avoid changing localStorageModule.js
because I'm installing dependencies from bower.
It looks like you have a package.json
, but the latest version available on npm is 0.0.1
. Can you publish your more recent code?
(Also, it looks like there are some dependencies
in package.json
that should really be devDependencies
.)
Thanks!
Hello, nice library! I was hoping you could add support for storing objects. When I attempt to store an object, it stores as [object Object]
and gets the same - rendering the result useless.
I've seen this handled before in https://github.com/jeromegn/Backbone.localStorage by stringifying the object on save and decoding on read. Although, I dont think this library needs to go so far as to replicate a noSQL database (as the backbone library does).
As an idea on how to implement, we could modify the add(key, value)
method to check if typeof value === "object"
and thes stringify the value. I assume something similar when reading values.
Thoughts?
-Matt
There is a problem with angular-local-storage.min.js, unlike angular-local-storage.js (without "min"). It is probably outdated.
Personally, I would prefer to have the fallback (the implementation) to cookies optional - maybe through a build script (like Grunt).
Apart from that, why not using $cookies service from the ngCookies module?
What's the license for this project?
if 0.0.1 version is done, please tag it in github so we can force version in bower install :)
localStorageService.add("wat", 99)
//=> true
localStorageService.get("wat")
//=>"99"
Hi there, does this library support watching a given key in the localStorage? This way I could keep my app state synced in multiple tabs.
Thanks.
For you know, settings default params and stuff. Since services can't be injected into config block, it'd have to be a provider or something..
It's possible to auto bind local storage values in the rootScope ?
I have an abstract parent controller with a child state using ui-router. When I refresh the page I get an undefined error for localStorageService.get. It looks like I have the provider instead of the service immediately after a refresh ( which is when I would want the service to work )
Does this module serialize the values? I guess it does for arrays, but what about other objects?
When I made a round trip (set and then get) my numeric values came back as strings.
localStorageService.set("page_number", n); // n === 1
n = localStorageService.get("page_number"); // n === "1"
np, I fixed it with:
n = parseInt(localStorageService.get("page_number"), 10);
but I thinkit would be better to preserve the basic JSON types.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.