Skip to content

Commit 260a8eb

Browse files
author
Michael Buckley
committed
Support binding objects to nested scope values
1 parent 7729df6 commit 260a8eb

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/angular-local-storage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ angularLocalStorage.provider('localStorageService', function() {
383383

384384
return scope.$watch(key, function(newVal) {
385385
addToLocalStorage(lsKey, newVal);
386-
}, isObject(scope[key]));
386+
}, isObject(value));
387387
};
388388

389389
// Return localStorageService.length

test/spec/localStorageSpec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,23 @@ describe('localStorageService', function() {
421421
expect(results).toEqual(expectation);
422422
}));
423423

424+
it('should $watch with deep comparison for objects in nested scope properties', inject(function($rootScope, localStorageService) {
425+
var mocks = [{}, [], 'string', 90, false];
426+
var expectation = [true, true, false, false, false];
427+
var results = [];
428+
429+
spyOn($rootScope, '$watch').andCallFake(function(key, func, eq) {
430+
results.push(eq);
431+
});
432+
433+
mocks.forEach(function(elm, i) {
434+
localStorageService.set('mock' + i, elm);
435+
localStorageService.bind($rootScope, 'nested.mock' + i, null, 'mock' +i);
436+
});
437+
438+
expect(results).toEqual(expectation);
439+
}));
440+
424441
it('should be able to return it\'s owned keys amount', inject(
425442
function(localStorageService, $window) {
426443

0 commit comments

Comments
 (0)