From ae13ec45fde5a32f3ef73c7689879a445593acf7 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Thu, 9 Oct 2014 14:45:57 +0300 Subject: [PATCH] fix(README): getting started doc + cookies doc --- README.md | 133 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 89 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 64fa1d6..7a78e41 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ An Angular module that gives you access to the browsers local storage, **v0.1.1* [![Build Status](https://secure.travis-ci.org/grevory/angular-local-storage.png?branch=master)](https://travis-ci.org/grevory/) ##Table of contents: +- [Get Started](#get-started) - [Configuration](#configuration) - [setPrefix](#setprefix) - [setStorageType](#setstoragetype) @@ -24,7 +25,49 @@ An Angular module that gives you access to the browsers local storage, **v0.1.1* - [bind](#bind) - [deriveKey](#derivekey) - [length](#length) + - [cookie](#cookie) + - [set](#cookie.set) + - [get](#cookie.get) + - [remove](#cookie.remove) + - [clearAll](#cookie.clearall) +##Get Started +**(1)** You can install angular-local-storage using 2 different ways:
+**Git:** +clone & build [this](https://github.com/grevory/angular-local-storage.git) repository
+**Bower:** +```bash +$ bower install angular-local-storage +``` +**npm:** +```bash +$ npm install angular-local-storage +``` +**(2)** Include `angular-local-storage.js` (or `angular-local-storage.min.js`) in your `index.html`, after including Angular itself. + +**(3)** Add `'LocalStorageModule'` to your main module's list of dependencies. + +When you're done, your setup should look similar to the following: + +```html + + + + + + + ... + + + ... + + ... + + +``` ##Configuration ###setPrefix You could set a prefix to avoid overwriting any local storage variables from the rest of your app
@@ -132,7 +175,7 @@ myApp.controller('MainCtrl', function($scope, localStorageService) { }); ``` ###keys -Return array of keys for local storage, ignore keys that not owned. +Return array of keys for local storage, ignore keys that not owned.
**Returns:** `value from local storage` ```js myApp.controller('MainCtrl', function($scope, localStorageService) { @@ -207,52 +250,54 @@ myApp.controller('MainCtrl', function($scope, localStorageService) { //... }); ``` - -##Installation: - -```bash -$ bower install angular-local-storage +##Cookie +Deal with browser's cookies directly. +###cookie.set +Directly adds a value to cookies.
+**Note:** Typically used as a fallback if local storage is not supported.
+**Returns:** `Boolean` +```js +myApp.controller('MainCtrl', function($scope, localStorageService) { + //... + function submit(key, val) { + return localStorageService.cookie.set(key, value); + } + //... +}); ``` - -Example use: - -```javascript -angular.module('yourModule', ['LocalStorageModule']) -.controller('yourCtrl', [ - '$scope', - 'localStorageService', - function($scope, localStorageService) { - // Start fresh - localStorageService.clearAll(); - - // Set a key - localStorageService.set('Favorite Sport','Ultimate Frisbee'); - - // Delete a key - localStorageService.remove('Favorite Sport'); -}]); - -/* -To set the prefix of your localStorage name, you can use the setPrefix method -available on the localStorageServiceProvider -*/ -angular.module('yourModule', ['LocalStorageModule']) -.config(['localStorageServiceProvider', function(localStorageServiceProvider){ - localStorageServiceProvider.setPrefix('newPrefix'); -}]); +###cookie.get +Directly get a value from a cookie.
+**Returns:** `value from local storage` +```js +myApp.controller('MainCtrl', function($scope, localStorageService) { + //... + function getItem(key) { + return localStorageService.cookie.get(key); + } + //... +}); ``` - -#### How to bind to a $scope variable: -Usage: localStorageService.bind(scope, scopeKey, def, lsKey); +###cookie.remove +Remove directly value from a cookie.
+**Returns:** `Boolean` +```js +myApp.controller('MainCtrl', function($scope, localStorageService) { + //... + function removeItem(key) { + return localStorageService.cookie.remove(key); + } + //... +}); ``` -// Example -$scope.anArtist = {'firstname':'Pablo', 'lastname':'Picasso'}; - -// Bind to local storage service -localStorageService.bind($scope, 'anArtist', $scope.anArtist, 'specialArtist'); - -// get bound data: -console.log(localStorageService.get('specialArtist')); +###clearAll +Remove all data for this app from cookie.
+```js +myApp.controller('MainCtrl', function($scope, localStorageService) { + //... + function clearAll() { + return localStorageService.cookie.clearAll(); + } +}); ``` Check out the full demo and documentation at http://gregpike.net/demos/angular-local-storage/demo.html