angular-swx-session-storage
Version:
$sessionStorage service for use in your AngularJS applications.
67 lines (65 loc) • 5.03 kB
HTML
<h1><code ng:non-bindable="">$sessionStorage</code>
<div><span class="hint"></span>
</div>
</h1>
<div><h2 id="description">Description</h2>
<div class="description"><div class="-sessionstorage-page"><p>Provides a key-value (string-object) session storage with expiry option (in minutes).</p>
</div></div>
<h2 id="dependencies">Dependencies</h2>
<ul class="dependencies"><li><code ng:non-bindable=""><a href="api/ng.$window">$window</a></code>
</li>
<li><code ng:non-bindable=""><a href="api/ng.$location">$location</a></code>
</li>
<li><code ng:non-bindable=""><a href="api/ng.$cacheFactory">$cacheFactory</a></code>
</li>
</ul>
<h2 id="usage">Usage</h2>
<div class="usage"><pre class="prettyprint linenums">$sessionStorage($window, $location, $cacheFactory);</pre>
<h4 id="usage_parameters">Parameters</h4><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>$window</td><td><a href="" class="label type-hint type-hint-service">service</a></td><td><div class="-sessionstorage-page"><p>The $window service.</p>
</div></td></tr><tr><td>$location</td><td><a href="" class="label type-hint type-hint-service">service</a></td><td><div class="-sessionstorage-page"><p>The $location service.</p>
</div></td></tr><tr><td>$cacheFactory</td><td><a href="" class="label type-hint type-hint-service">service</a></td><td><div class="-sessionstorage-page"><p>The $cacheFactory service.</p>
</div></td></tr></tbody></table></div>
<div class="member method"><h2 id="methods">Methods</h2>
<ul class="methods"><li><h3 id="methods_empty">empty()</h3>
<div class="empty"><div class="-sessionstorage-empty-page"><p>Delete all data from session storage and cookie.</p>
</div></div>
</li>
<li><h3 id="methods_get">get(key)</h3>
<div class="get"><div class="-sessionstorage-get-page"><p>Get data from storage, will return from session cache if possible for greater performance.</p>
</div><h5 id="methods_get_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>key</td><td><a href="" class="label type-hint type-hint-string">String</a></td><td><div class="-sessionstorage-get-page"><p>The key of the stored data to retrieve.</p>
</div></td></tr></tbody></table><h5 id="methods_get_returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-object">*</a></td><td><div class="-sessionstorage-get-page"><p>The value of the stored data or undefined.</p>
</div></td></tr></table></div>
</li>
<li><h3 id="methods_prefix">prefix(val)</h3>
<div class="prefix"><div class="-sessionstorage-prefix-page"><p>Overrides the default domain prefix.</p>
<p><strong>N.B. Destroys the existing cache.</strong></p>
</div><h5 id="methods_prefix_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>val</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="-sessionstorage-prefix-page"><p>The string to add to the persistent data prefix.</p>
</div></td></tr></tbody></table><h4 id="methods_prefix_example">Example</h4>
<div class="example"><div class="-sessionstorage-prefix-page"><pre><code class="lang-js">$sessionStorage.prefix('myPrefix');
</code></pre>
</div></div>
</div>
</li>
<li><h3 id="methods_put">put(key, value)</h3>
<div class="put"><div class="-sessionstorage-put-page"><p>Add data to storage</p>
</div><h5 id="methods_put_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>key</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="-sessionstorage-put-page"><p>The key to store the data with.</p>
</div></td></tr><tr><td>value</td><td><a href="" class="label type-hint type-hint-object">*</a></td><td><div class="-sessionstorage-put-page"><p>The data to store.
[@param {number} expires] (expiry in minutes)</p>
</div></td></tr></tbody></table></div>
</li>
<li><h3 id="methods_remove">remove(key)</h3>
<div class="remove"><h5 id="methods_remove_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>key</td><td><a href="" class="label type-hint type-hint-string">String</a></td><td><div class="-sessionstorage-remove-page"><p>The key of the stored data to remove.</p>
</div></td></tr></tbody></table></div>
</li>
</ul>
</div>
<h2 id="example">Example</h2>
<div class="example"><div class="-sessionstorage-page"><pre><code class="lang-js">myApp.$inject = ['$sessionStorage'];
function myApp($sessionStorage) {
// Your app code...
}
angular
.module('myApp', ['swxSessionStorage']);
</code></pre>
</div></div>
</div>