I doubt this is Ionic 2 specific, but I'm having some trouble syncing my local PouchDB database to a remote Cloudant database. Maybe my code just needs a sanity check, but absolutely nothing is happening when I try to sync.
Here's the provider I created to handle it:
import {Storage, SqlStorage} from 'ionic/ionic';
import {Injectable} from 'angular2/core';
var PouchDB = require('pouchdb');
//To enable debugging with the PouchDB Inspector Plugin
window.PouchDB = PouchDB;
@Injectable()
export class DataService {
constructor(){
this.db = new PouchDB('todos');
this.username = 'myuser';
this.password = 'mypass';
this.remote = 'https://' + this.username + ':' + this.password + '@myuser.cloudant.com/todos';
let options = {
live: true,
retry: true
};
this.db.sync(this.remote, options);
}
getData() {
return new Promise(resolve => {
this.db.allDocs({
include_docs: true
}).then((result) => {
this.data = [];
let docs = result.rows.map((row) => {
this.data.push(row.doc);
});
resolve(this.data);
}).catch((error) => {
console.log(error);
});
});
}
addItem(item, listPage){
this.db.put(item);
listPage.loadItems();
}
updateItem(item){
return this.db.put(item);
}
removeItem(item){
this.db.get(item._id).then((doc) => {
return this.db.remove(doc);
});
}
}
I can add and fetch data with PouchDB fine locally, but the sync code in the constructor doesn't do anything. It executes, but there is no network requests to the database, no errors, just nothing happens. Even if I mangle the URL to the remote database it still doesn't do anything so I'm reasonably sure it's not a Cloudant issue.
Any thoughts?