TypeError: Cannot read property ‘post’ of undefined
at EmployeeProvider.webpackJsonp.100.EmployeeProvider.create (http://localhost:8100/build/main.js:32:25)
at EmployeePage.webpackJsonp.201.EmployeePage.addOrUpdate (http://localhost:8100/build/main.js:211:35)
at Object.eval [as handleEvent] (ng:///AppModule/EmployeePage.ngfactory.js:129:27)
at handleEvent (http://localhost:8100/build/vendor.js:13963:155)
at callWithDebugContext (http://localhost:8100/build/vendor.js:15472:42)
at Object.debugHandleEvent [as handleEvent] (http://localhost:8100/build/vendor.js:15059:12)
at dispatchEvent (http://localhost:8100/build/vendor.js:10378:25)
at http://localhost:8100/build/vendor.js:11003:38
at HTMLButtonElement. (http://localhost:8100/build/vendor.js:39492:53)
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660)
====
import { Injectable } from ‘@angular/core’;
import { Http } from ‘@angular/http’;
import ‘rxjs/add/operator/map’;
import * as PouchDB from ‘pouchdb’;
import cordovaSqlitePlugin from ‘pouchdb-adapter-cordova-sqlite’;
@Injectable()
export class EmployeeProvider {
public pdb;
public employees;
createPouchDB() {
PouchDB.plugin(cordovaSqlitePlugin);
this.pdb = new PouchDB(‘employees.db’,
{ adapter: ‘cordova-sqlite’ });
}
create(employee) {
return this.pdb.post(employee);
}
update(employee) {
return this.pdb.put(employee);
}
delete(employee) {
return this.pdb.delete(employee);
}
read() {
function allDocs(){
this.pdb.allDocs({ include_docs: true})
.then(docs => {
this.employees = docs.rows.map(row => {
row.doc.Date = new Date(row.doc.Date);
return row.doc;
});
return this.employees;
});
}
/*
this.pdb.changes({ live: true, since: ‘now’, include_docs: true})
.on(‘change’, ()=>{
allDocs().then((emps)=>{
this.employees = emps;
});
});
*/
return allDocs();
}
}