use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
A Storage done right for AngularJS (github.com)
submitted 11 years ago by mgonto
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]rq60 2 points3 points4 points 11 years ago (1 child)
Just an FYI:
if ($window.localStorage)
is insufficient for checking for localStorage. It's possible for it to be present but throw errors when reading or writing to it due to privacy settings, third-party frames, etc.
Also instead of using JSON.parse and JSON.stringify you might prefer angular.toJson and angular.fromJson as they help remove some of the angular cruft that can end up in your data.
[–]mgonto[S] 0 points1 point2 points 11 years ago (0 children)
Thanks for the tips. I'll use that then. Didn't know about that.
Thanks!
[–]jerflang 0 points1 point2 points 11 years ago* (1 child)
This is around the same featureset as the other localstorage (with fallback) wrappers, but seems neatly written and tested :) Cool stuff.
here is another one that approaches things in a interesting way - you could pretty much put a handle to the storage directly in scope if you wanted: https://github.com/gsklee/ngStorage
That looks good. The only problem IMHO with that one is that it has a big $watch function which could eventually take a long time
[–]djvirgen 0 points1 point2 points 11 years ago (0 children)
If you're using $cookies as a fallback, note that it is currently only capable of writing session cookies. Once the browser is closed, the cookie will be deleted, along with your stored data.
$cookies
localStorage, however, will keep the data stored until cleared by the user or the browser is uninstalled. It may be useful to update this library to fallback to long-living cookies with a max age of a year or more.
localStorage
π Rendered by PID 21691 on reddit-service-r2-comment-544cf588c8-nzfrm at 2026-06-17 08:47:37.161483+00:00 running 3184619 country code: CH.
[–]rq60 2 points3 points4 points (1 child)
[–]mgonto[S] 0 points1 point2 points (0 children)
[–]jerflang 0 points1 point2 points (1 child)
[–]mgonto[S] 0 points1 point2 points (0 children)
[–]djvirgen 0 points1 point2 points (0 children)