Update README.

master
Yihang Ho 10 years ago
parent 0b8d7820e9
commit 0ff995d63b

@ -11,7 +11,7 @@ Installation:
bower install angular-local-storage bower install angular-local-storage
``` ```
Example use: Example use:
```javascript ```javascript
angular.module('yourModule', ['LocalStorageModule']) angular.module('yourModule', ['LocalStorageModule'])
@ -21,16 +21,16 @@ angular.module('yourModule', ['LocalStorageModule'])
function($scope, localStorageService) { function($scope, localStorageService) {
// Start fresh // Start fresh
localStorageService.clearAll(); localStorageService.clearAll();
// Set a key // Set a key
localStorageService.set('Favorite Sport','Ultimate Frisbee'); localStorageService.set('Favorite Sport','Ultimate Frisbee');
// Delete a key // Delete a key
localStorageService.delete('Favorite Sport'); localStorageService.delete('Favorite Sport');
}]); }]);
/* /*
To set the prefix of your localStorage name, you can use the setPrefix method To set the prefix of your localStorage name, you can use the setPrefix method
available on the localStorageServiceProvider available on the localStorageServiceProvider
*/ */
angular.module('yourModule', ['LocalStorageModule']) angular.module('yourModule', ['LocalStorageModule'])
@ -40,16 +40,16 @@ angular.module('yourModule', ['LocalStorageModule'])
``` ```
#### How to bind to a $scope variable: #### How to bind to a $scope variable:
Usage: localStorageService.bind(scope, key, def); Usage: localStorageService.bind(scope, scopeKey, def, lsKey);
``` ```
// Example // Example
$scope.anArtist = {'firstname':'Pablo', 'lastname':'Picasso'}; $scope.anArtist = {'firstname':'Pablo', 'lastname':'Picasso'};
// Bind to local storage service // Bind to local storage service
localStorageService.bind($scope, 'anArtist', anArtist); localStorageService.bind($scope, 'anArtist', $scope.anArtist, 'specialArtist');
// get bound data: // get bound data:
console.log(localStorageService.get('anArtist')); console.log(localStorageService.get('specialArtist'));
``` ```
Check out the full demo and documentation at http://gregpike.net/demos/angular-local-storage/demo.html Check out the full demo and documentation at http://gregpike.net/demos/angular-local-storage/demo.html