Angular JS – IndexedDB DataCloneError when storing $resource

Mar 4, 2014 by

In an AngularJS Google Chrome App that I’m writing, I keep getting a frustrating error when attempting to store data from a remote resource.

After searching around, I realised it was because there were references to cyclic objects (the angular $promise objects within the $resource object), so using a slight adaption to code I found within angular JS itself, I was able to remove the offending item before storing to the DB.

* Create a shallow copy of an object and clear other fields from the destination - see
function shallowClearAndCopy(src, dst) {
dst = dst || {};

angular.forEach(dst, function(value, key){
delete dst[key];

for (var key in src) {
if (src.hasOwnProperty(key) && (!(key.charAt(0) === ‘$’ || key.charAt(1) === ‘$’))) {
dst[key] = src[key];

return dst;

Related Posts


Share This