Last active
October 26, 2015 22:15
-
-
Save pankajpatel/295ed350eb60404c16fb to your computer and use it in GitHub Desktop.
Storage Module written in AngularJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular | |
.module('storageModule', []) | |
.factory('store',['$window', function($window){ | |
return { | |
setLocal: function( key, value ){ | |
try{ | |
if( $window.Storage ){ | |
$window.localStorage.setItem(key, value); | |
return true; | |
} else { | |
return false; | |
} | |
} catch( error ){ | |
console.error( error, error.message ); | |
} | |
}, | |
getLocal: function( key ){ | |
try{ | |
if( $window.Storage ){ | |
return $window.localStorage.getItem( key ); | |
} else { | |
return false; | |
} | |
} catch( error ){ | |
console.error( error, error.message ); | |
} | |
}, | |
setSession: function( key, value ){ | |
try{ | |
if( $window.Storage ){ | |
$window.sessionStorage.setItem( key, value ); | |
return true; | |
} else { | |
return false; | |
} | |
} catch( error ){ | |
console.error( error, error.message ); | |
} | |
}, | |
getSession: function( key ){ | |
try{ | |
if( $window.Storage ){ | |
return $window.sessionStorage.getItem( key ); | |
} else { | |
return false; | |
} | |
} catch( error ){ | |
console.error( error, error.message ); | |
} | |
} | |
} | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment