Skip to content

Commit a425b43

Browse files
committed
feat(localStorageService): improve .bind func, issue #144
1 parent aef73ba commit a425b43

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/angular-local-storage.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,8 @@ angularLocalStorage.provider('localStorageService', function() {
367367

368368
// Add a listener on scope variable to save its changes to local storage
369369
// Return a function which when called cancels binding
370-
var bindToScope = function(scope, scopeKey, def, lsKey) {
371-
if (!lsKey) {
372-
lsKey = scopeKey;
373-
}
374-
370+
var bindToScope = function(scope, key, def, lsKey) {
371+
lsKey = lsKey || key;
375372
var value = getFromLocalStorage(lsKey);
376373

377374
if (value === null && isDefined(def)) {
@@ -380,11 +377,11 @@ angularLocalStorage.provider('localStorageService', function() {
380377
value = extend(def, value);
381378
}
382379

383-
$parse(scopeKey).assign(scope, value);
380+
$parse(key).assign(scope, value);
384381

385-
return scope.$watchCollection(scopeKey, function(newVal) {
382+
return scope.$watch(key, function(newVal) {
386383
addToLocalStorage(lsKey, newVal);
387-
});
384+
}, isObject(scope[key]));
388385
};
389386

390387
// Return localStorageService.length

0 commit comments

Comments
 (0)