@@ -13,6 +13,14 @@ An Angular module that gives you access to the browsers local storage, **v0.1.1*
13
13
- [ setStorageCookieDomain] ( #setstoragecookiedomain )
14
14
- [ setNotify] ( #setnotify )
15
15
- [ Example] ( #configuration-example )
16
+ - [ API Documentation] ( #api-documentation )
17
+ - [ isSupported] ( #issupported )
18
+ - [ getStorageType] ( #getstoragetype )
19
+ - [ set] ( #set )
20
+ - [ get] ( #get )
21
+ - [ keys] ( #keys )
22
+ - [ remove] ( #remove )
23
+ - [ clearAll] ( #clearall )
16
24
17
25
##Configuration
18
26
###setPrefix
@@ -72,6 +80,94 @@ myApp.config(function (localStorageServiceProvider) {
72
80
.setNotify (true , true )
73
81
});
74
82
```
83
+ ##API Documentation
84
+ ##isSupported
85
+ Checks if the browser support the current storage type(e.g: ` localStorage ` , ` sessionStorage ` ).
86
+ ** Returns:** ` Boolean `
87
+ ``` js
88
+ myApp .controller (' MainCtrl' , function ($scope , localStorageService ) {
89
+ // ...
90
+ if (localStorageService .isSupported ()) {
91
+ // ...
92
+ }
93
+ // ...
94
+ });
95
+ ```
96
+ ###getStorageType
97
+ ** Returns:** ` String `
98
+ ``` js
99
+ myApp .controller (' MainCtrl' , function ($scope , localStorageService ) {
100
+ // ...
101
+ var storageType = localStorageService .getStorageType (); // e.g localStorage
102
+ // ...
103
+ });
104
+ ```
105
+ ###set
106
+ Directly adds a value to local storage.<br />
107
+ If local storage is not supported, use cookies instead.<br />
108
+ ** Returns:** ` Boolean `
109
+ ``` js
110
+ myApp .controller (' MainCtrl' , function ($scope , localStorageService ) {
111
+ // ...
112
+ function submit (key , val ) {
113
+ return localStorageService .set (key, value);
114
+ }
115
+ // ...
116
+ });
117
+ ```
118
+ ###get
119
+ Directly get a value from local storage.<br />
120
+ If local storage is not supported, use cookies instead.<br />
121
+ ** Returns:** ` value from local storage `
122
+ ``` js
123
+ myApp .controller (' MainCtrl' , function ($scope , localStorageService ) {
124
+ // ...
125
+ function getItem (key ) {
126
+ return localStorageService .get (key);
127
+ }
128
+ // ...
129
+ });
130
+ ```
131
+ ###keys
132
+ Return array of keys for local storage, ignore keys that not owned.
133
+ ** Returns:** ` value from local storage `
134
+ ``` js
135
+ myApp .controller (' MainCtrl' , function ($scope , localStorageService ) {
136
+ // ...
137
+ var lsKeys = localStorageService .keys ();
138
+ // ...
139
+ });
140
+ ```
141
+ ###remove
142
+ Remove an item from local storage by key.<br />
143
+ If local storage is not supported, use cookies instead.<br />
144
+ ** Returns:** ` Boolean `
145
+ ``` js
146
+ myApp .controller (' MainCtrl' , function ($scope , localStorageService ) {
147
+ // ...
148
+ function removeItem (key ) {
149
+ return localStorageService .remove (key);
150
+ }
151
+ // ...
152
+ });
153
+ ```
154
+ ###clearAll
155
+ Remove all data for this app from local storage.<br />
156
+ If local storage is not supported, use cookies instead.<br />
157
+ ** Note:** Optionally takes a regular expression string and removes matching.<br />
158
+ ** Returns:** ` Boolean `
159
+ ``` js
160
+ myApp .controller (' MainCtrl' , function ($scope , localStorageService ) {
161
+ // ...
162
+ function clearNumbers (key ) {
163
+ return localStorageService .clearAll (/ ^ \d + $ / );
164
+ }
165
+
166
+ function clearAll () {
167
+ return localStorageService .clearAll ();
168
+ }
169
+ // ...
170
+ });
75
171
76
172
##Installation:
77
173
0 commit comments