I am currently looking for a software/web development job preferably as a Rails-based developer.
Please email me at weston@westonganger.com. Thanks in advance for any leads!

How To Use LocalStorage In AngularJS

Posted by Weston Ganger

With all apps these days local storage can be used for anything. Its awesome.

My favourite is to use the ngStorage module for both local storage and session storage.

The simple alternative is to create a small angular service to interact which works perfect too.

yourApp.factory('$localstorage', ['$window', function($window) {
  return {
    set: function(key, value) {
      $window.localStorage[key] = value;
    get: function(key, defaultValue) {
      return $window.localStorage[key] || defaultValue || false;
    setObject: function(key, value) {
      $window.localStorage[key] = JSON.stringify(value);
    getObject: function(key, defaultValue) {
      if($window.localStorage[key] != undefined){
          return JSON.parse($window.localStorage[key]);
        return defaultValue || false;
    remove: function(key){
    clear: function(){

Related External Links:

Article Topic:Software Development - Angular

Date:March 07, 2016

Recommended Posts