Skip to content

Commit

Permalink
Support binding objects to nested scope values
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Buckley committed May 26, 2015
1 parent 7729df6 commit 260a8eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/angular-local-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ angularLocalStorage.provider('localStorageService', function() {

return scope.$watch(key, function(newVal) {
addToLocalStorage(lsKey, newVal);
}, isObject(scope[key]));
}, isObject(value));
};

// Return localStorageService.length
Expand Down
17 changes: 17 additions & 0 deletions test/spec/localStorageSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,23 @@ describe('localStorageService', function() {
expect(results).toEqual(expectation);
}));

it('should $watch with deep comparison for objects in nested scope properties', inject(function($rootScope, localStorageService) {
var mocks = [{}, [], 'string', 90, false];
var expectation = [true, true, false, false, false];
var results = [];

spyOn($rootScope, '$watch').andCallFake(function(key, func, eq) {
results.push(eq);
});

mocks.forEach(function(elm, i) {
localStorageService.set('mock' + i, elm);
localStorageService.bind($rootScope, 'nested.mock' + i, null, 'mock' +i);
});

expect(results).toEqual(expectation);
}));

it('should be able to return it\'s owned keys amount', inject(
function(localStorageService, $window) {

Expand Down

0 comments on commit 260a8eb

Please sign in to comment.