demo.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <!doctype html>
  2. <html lang="en">
  3. <meta charset="utf-8">
  4. <title>Demo of Angular Local Storage Module</title>
  5. <meta name="description" content="Demo of Angular Local Storage Module">
  6. <meta name="author" content="Gregory Pike">
  7. <link rel="stylesheet" href="http://necolas.github.com/normalize.css/2.0.1/normalize.css">
  8. <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/css/bootstrap-combined.min.css" rel="stylesheet">
  9. <link href="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css" rel="stylesheet">
  10. <link href="demo-style.css" rel="stylesheet">
  11. <!--[if lt IE 9]>
  12. <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  13. <![endif]-->
  14. <body onload="prettyPrint()">
  15. <!-- BEGIN DEMO -->
  16. <div class="container" ng-app="demoModule">
  17. <div class="navbar navbar-inverse">
  18. <div class="navbar-inner">
  19. <a class="brand" href="#">Angular Local Storage</a>
  20. </div>
  21. </div>
  22. <div class="hero-unit">
  23. <h1>Give it a try</h1>
  24. <div ng-controller="DemoCtrl">
  25. <p><input type="text" ng-model="localStorageDemo" placeholder="Start typing..."></p>
  26. <blockquote class="well" ng-show="localStorageDemoValue">
  27. <p ng-bind="localStorageDemoValue"></p>
  28. <small>{{storageType}} value</small>
  29. </blockquote>
  30. <p><button ng-click="clearAll()">Clear All</button></p>
  31. </div>
  32. <p>The Angular Local Storage Module is meant to be a plug-and-play Angular module for accessing the browsers Local Storage API.</p>
  33. </div>
  34. <p>Angular Local Storage offers you access to the browser local storage API through Angular but also allows has the following features:</p>
  35. <ul>
  36. <li>Control local storage access through key prefices (e.g. "myApp.keyName")</li>
  37. <li>Checks browser support and falls back to cookies for antiquated browsers</li>
  38. <li>Allows programmatic access to remove all keys for a given app</li>
  39. </ul>
  40. <h3>Usage</h3>
  41. <!-- Sorry guys, I need to earn a living -->
  42. <div style="float: right">
  43. <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
  44. <!-- ALS Leaderboard -->
  45. <ins class="adsbygoogle"
  46. style="display:inline-block;width:728px;height:90px"
  47. data-ad-client="ca-pub-8242772837340688"
  48. data-ad-slot="1586567981"></ins>
  49. <script>
  50. (adsbygoogle = window.adsbygoogle || []).push({});
  51. </script>
  52. </div>
  53. <h6>Dependencies:</h6>
  54. <ul>
  55. <li><code>AngularJS</code> <small><a href="http://angularjs.org/">http://angularjs.org/</a></small></li>
  56. <li><code>Angular Local Storage Module</code> <small><a href="../src/angular-local-storage.js">angular-local-storage.js</a></small></li>
  57. </ul>
  58. <h6>JS Example</h6>
  59. <pre class="prettyprint lang-js">
  60. var YourCtrl = function($scope, localStorageService, ...) {
  61. // To add to local storage
  62. localStorageService.set('localStorageKey','Add this!');
  63. // Read that value back
  64. var value = localStorageService.get('localStorageKey');
  65. // To remove a local storage
  66. localStorageService.remove('localStorageKey');
  67. // Removes all local storage
  68. localStorageService.clearAll();
  69. // You can also play with cookies the same way
  70. localStorageService.cookie.set('localStorageKey','I am a cookie value now');
  71. }</pre>
  72. <h3>API Access</h3>
  73. <table class="table table-striped table-bordered">
  74. <thead>
  75. <tr>
  76. <th>Call</th>
  77. <th>Arguments</th>
  78. <th>Action</th>
  79. <th>Returns</th>
  80. </tr>
  81. </thead>
  82. <tbody>
  83. <tr>
  84. <td><code>isSupported</code></td>
  85. <td class="muted"><small>n/a</small></td>
  86. <td>Checks the browsers support for local storage</td>
  87. <td>Boolean for success</td>
  88. </tr>
  89. <tr>
  90. <td><code>set</code></td>
  91. <td><small>key, value</small></td>
  92. <td>Adds a key-value pair to the browser local storage</td>
  93. <td>Boolean for success</td>
  94. </tr>
  95. <tr>
  96. <td><code>get</code></td>
  97. <td><small>key</small></td>
  98. <td>Gets a value from local storage</td>
  99. <td>Stored value</td>
  100. </tr>
  101. <tr>
  102. <td><code>remove</code></td>
  103. <td><small>key, ...</small></td>
  104. <td>Removes a key-value pairs from the browser local storage</td>
  105. <td>n/a</td>
  106. </tr>
  107. <tr>
  108. <td><code>clearAll</code></td>
  109. <td class="muted">n/a</td>
  110. <td><span class="label label-warning">Warning</span> Removes all local storage key-value pairs for this app. It will optionally take a string, which is converted to a regular expression, and then clears keys based on that regular expression.</td>
  111. <td>Boolean for success</td>
  112. </tr>
  113. <tr>
  114. <td><code>cookie</code></td>
  115. <td><small>set | get | remove | clearAll</small></td>
  116. <td>Each function within cookie uses the same arguments as the coresponding local storage functions</td>
  117. <td>n/a</td>
  118. </tr>
  119. </tbody>
  120. </table>
  121. </div>
  122. <!-- END DEMO -->
  123. <!-- JAVASCRIPT -->
  124. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
  125. <script src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js"></script>
  126. <script src="https://rawgit.com/grevory/angular-local-storage/master/dist/angular-local-storage.min.js"></script>
  127. <script src="demo-app.js"></script>
  128. </body>
  129. </html>