feat(localStorageService): improve .bind func, issue #144

master
Ariel Mashraki 10 years ago
parent aef73ba676
commit a425b43caa

@ -367,11 +367,8 @@ angularLocalStorage.provider('localStorageService', function() {
// Add a listener on scope variable to save its changes to local storage // Add a listener on scope variable to save its changes to local storage
// Return a function which when called cancels binding // Return a function which when called cancels binding
var bindToScope = function(scope, scopeKey, def, lsKey) { var bindToScope = function(scope, key, def, lsKey) {
if (!lsKey) { lsKey = lsKey || key;
lsKey = scopeKey;
}
var value = getFromLocalStorage(lsKey); var value = getFromLocalStorage(lsKey);
if (value === null && isDefined(def)) { if (value === null && isDefined(def)) {
@ -380,11 +377,11 @@ angularLocalStorage.provider('localStorageService', function() {
value = extend(def, value); value = extend(def, value);
} }
$parse(scopeKey).assign(scope, value); $parse(key).assign(scope, value);
return scope.$watchCollection(scopeKey, function(newVal) { return scope.$watch(key, function(newVal) {
addToLocalStorage(lsKey, newVal); addToLocalStorage(lsKey, newVal);
}); }, isObject(scope[key]));
}; };
// Return localStorageService.length // Return localStorageService.length