我正在使用LocalStorageModule
。
myApp.factory('myService', function($rootScope, localStorageService) {
return {
addSomething : function(name) {
...
var ret = localStorageService.set('something', lotsOfData);
alert(ret);
return ret;
}
}
}
在这种情况下,ret
为true
,即使数据尚未成功添加或未更改。有没有办法检查添加是否有效?
答案 0 :(得分:0)
您只需读取存储在本地存储中的数据,并将其与预期值进行比较:
localStorageService.set('foo', foo);
if (!angular.equals(localStorageService.get('foo'), foo)) {
throw "The data hasn't been successfully added to the local storage.";
}