bramski / angular-indexedDB

An angularjs serviceprovider to utilize indexedDB with angular
165 stars 49 forks source link

Failed to execute 'add' on 'IDBObjectStore': An object could not be cloned. #11

Closed Lunatic83 closed 9 years ago

Lunatic83 commented 9 years ago

Hi bramski I have a problem using angular-indexedDB module with Restangular. Failed to execute 'add' on 'IDBObjectStore': An object could not be cloned. I try to run: Restangular.one(entityName, id).get().then(function(result) { $indexedDB.openStore(entityName, function(table) { table.insert(result, function(result) { console.log('insert ok'); }); }); });

Is possible to use your module with Restangular or an openStore after a promise result?

Thanks for your help.

Gaspare

Lunatic83 commented 9 years ago

I fixed this, An object could not be cloned because, restangular return result with other function binded inside result object.

table.insert(result, function(result.plain())

bramski commented 9 years ago

Yes. You generally must only try and put simple objects into the indexed-db. I would generally recommend doing something like you have and standardizing your object representation before inserting it. It will make doing things like data migrations much simpler.