0
votes

I am trying to get sync() working between pouchDB and a local couchDB, within an Angular app (using angular-pouchdb).

  this.system =  pouchDB('system');
  var remoteSystem =  pouchDB('http://localhost:5984/system');

  this.system.sync(remoteSystem, {live : true}).on('change', function (change) {
    // yo, something changed!
    console.log('changed');
  }).on('error', function (err) {
    // yo, we got an error!
    console.log('error');
  });

but I keep getting the following error:

Uncaught TypeError: undefined is not a function (angular.js:4146)

If I remove the .on chains the error goes away (but the sync still doesn't work)

2

2 Answers

0
votes

The latest version of PouchDB has the sync method on the PouchDB object.

var remote = new PouchDB('http://localhost:5984/system');
var local = new PouchDB('system');

PouchDB.sync(local, remote, { live: true })
  .on('change', function (info) {
    // handle change
  }).on('complete', function (info) {
    // handle complete
  }).on('uptodate', function (info) {
    // handle up-to-date
  }).on('error', function (err) {
    // handle error
  });
0
votes

If you are using angular-pouchdb, then the pouchdb object is not really a PouchDB object; it's a special angular-pouchdb thing.

Luckily, the sync and replicate APIs are also available on the databases themselves. So you can do:

local.sync(remote, { live: true})

and it's the same thing.