fix(README.md): unbind doc

master
Ariel Mashraki 10 years ago
commit 45fd4c9d9d

@ -78,6 +78,7 @@ myApp.config(function (localStorageServiceProvider) {
.setPrefix('yourAppName');
});
```
<<<<<<< HEAD
###setStorageType
You could change web storage type to localStorage or sessionStorage<br/>
**Default storage:** `localStorage`
@ -217,16 +218,21 @@ myApp.controller('MainCtrl', function($scope, localStorageService) {
###bind
Bind $scope key to localStorageService.
**Usage:** `localStorageService.bind(scope, property, value[optional], key[optional])`
***key:*** The corresponding key used in local storage
***key:*** The corresponding key used in local storage
**Returns:** deregistration function for this listener.
```js
myApp.controller('MainCtrl', function($scope, localStorageService) {
//...
localStorageService.set('property', 'oldValue');
localStorageService.bind($scope, 'property');
var unbind = localStorageService.bind($scope, 'property');
//Test Changes
$scope.property = 'newValue';
console.log(localStorageService.get('property')) // newValue;
$scope.property = 'newValue1';
console.log(localStorageService.get('property')) // newValue1;
//unbind watcher
unbind();
$scope.property = 'newValue2';
console.log(localStorageService.get('property')) // newValue1;
//...
});
```
@ -302,7 +308,7 @@ myApp.controller('MainCtrl', function($scope, localStorageService) {
});
```
Check out the full demo and documentation at http://gregpike.net/demos/angular-local-storage/demo.html
Check out the full demo at http://gregpike.net/demos/angular-local-storage/demo.html
##TO DO:
- Expand Readme

@ -365,6 +365,8 @@ angularLocalStorage.provider('localStorageService', function() {
return storageType;
};
// Add a listener on scope variable to save its changes to local storage
// Return a function which when called cancels binding
var bindToScope = function(scope, scopeKey, def, lsKey) {
if (!lsKey) {
lsKey = scopeKey;
@ -380,7 +382,7 @@ angularLocalStorage.provider('localStorageService', function() {
$parse(scopeKey).assign(scope, value);
scope.$watchCollection(scopeKey, function(newVal) {
return scope.$watchCollection(scopeKey, function(newVal) {
addToLocalStorage(lsKey, newVal);
});
};

@ -277,6 +277,23 @@ describe('localStorageService', function() {
expect($rootScope.property).toEqual(localStorageService.get('property'));
}));
it('should be able to unbind from scope variable', inject(function($rootScope, localStorageService) {
localStorageService.set('property', 'oldValue');
var lsUnbind = localStorageService.bind($rootScope, 'property');
$rootScope.property = 'newValue';
$rootScope.$digest();
expect($rootScope.property).toEqual(localStorageService.get('property'));
lsUnbind();
$rootScope.property = 'anotherValue';
$rootScope.$digest();
expect($rootScope.property).not.toEqual(localStorageService.get('property'));
}));
it('should be able to bind to properties of objects', inject(function($rootScope, localStorageService) {
localStorageService.set('obj.property', 'oldValue');