44var angularLocalStorage = angular . module ( 'LocalStorageModule' , [ ] ) ;
55
66angularLocalStorage . provider ( 'localStorageService' , function ( ) {
7-
7+
88 // You should set a prefix to avoid overwriting any local storage variables from the rest of your app
99 // e.g. localStorageServiceProvider.setPrefix('youAppName');
1010 // With provider you can use config as this:
@@ -65,11 +65,11 @@ angularLocalStorage.provider('localStorageService', function() {
6565
6666
6767 this . $get = [ '$rootScope' , '$window' , '$document' , function ( $rootScope , $window , $document ) {
68-
69- var prefix = this . prefix ;
70- var cookie = this . cookie ;
71- var notify = this . notify ;
72- var storageType = this . storageType ;
68+ var self = this ;
69+ var prefix = self . prefix ;
70+ var cookie = self . cookie ;
71+ var notify = self . notify ;
72+ var storageType = self . storageType ;
7373 var webStorage ;
7474
7575 // When Angular's $document is not available
@@ -110,7 +110,7 @@ angularLocalStorage.provider('localStorageService', function() {
110110 return false ;
111111 }
112112 } ( ) ) ;
113-
113+
114114
115115
116116 // Directly adds a value to local storage
@@ -119,7 +119,7 @@ angularLocalStorage.provider('localStorageService', function() {
119119 var addToLocalStorage = function ( key , value ) {
120120
121121 // If this browser does not support local storage use cookies
122- if ( ! browserSupportsLocalStorage || this . storageType === 'cookie' ) {
122+ if ( ! browserSupportsLocalStorage || self . storageType === 'cookie' ) {
123123 $rootScope . $broadcast ( 'LocalStorageModule.notification.warning' , 'LOCAL_STORAGE_NOT_SUPPORTED' ) ;
124124 if ( notify . setItem ) {
125125 $rootScope . $broadcast ( 'LocalStorageModule.notification.setitem' , { key : key , newvalue : value , storageType : 'cookie' } ) ;
@@ -138,7 +138,7 @@ angularLocalStorage.provider('localStorageService', function() {
138138 }
139139 if ( webStorage ) { webStorage . setItem ( deriveQualifiedKey ( key ) , value ) } ;
140140 if ( notify . setItem ) {
141- $rootScope . $broadcast ( 'LocalStorageModule.notification.setitem' , { key : key , newvalue : value , storageType : this . storageType } ) ;
141+ $rootScope . $broadcast ( 'LocalStorageModule.notification.setitem' , { key : key , newvalue : value , storageType : self . storageType } ) ;
142142 }
143143 } catch ( e ) {
144144 $rootScope . $broadcast ( 'LocalStorageModule.notification.error' , e . message ) ;
@@ -151,7 +151,7 @@ angularLocalStorage.provider('localStorageService', function() {
151151 // Example use: localStorageService.get('library'); // returns 'angular'
152152 var getFromLocalStorage = function ( key ) {
153153
154- if ( ! browserSupportsLocalStorage || this . storageType === 'cookie' ) {
154+ if ( ! browserSupportsLocalStorage || self . storageType === 'cookie' ) {
155155 $rootScope . $broadcast ( 'LocalStorageModule.notification.warning' , 'LOCAL_STORAGE_NOT_SUPPORTED' ) ;
156156 return getFromCookies ( key ) ;
157157 }
@@ -184,7 +184,7 @@ angularLocalStorage.provider('localStorageService', function() {
184184 try {
185185 webStorage . removeItem ( deriveQualifiedKey ( key ) ) ;
186186 if ( notify . removeItem ) {
187- $rootScope . $broadcast ( 'LocalStorageModule.notification.removeitem' , { key : key , storageType : this . storageType } ) ;
187+ $rootScope . $broadcast ( 'LocalStorageModule.notification.removeitem' , { key : key , storageType : self . storageType } ) ;
188188 }
189189 } catch ( e ) {
190190 $rootScope . $broadcast ( 'LocalStorageModule.notification.error' , e . message ) ;
@@ -335,7 +335,7 @@ angularLocalStorage.provider('localStorageService', function() {
335335 var cookies = $document . cookie . split ( ';' ) ;
336336 for ( var i = 0 ; i < cookies . length ; i ++ ) {
337337 thisCookie = cookies [ i ] ;
338-
338+
339339 while ( thisCookie . charAt ( 0 ) === ' ' ) {
340340 thisCookie = thisCookie . substring ( 1 , thisCookie . length ) ;
341341 }
0 commit comments