javascript - Setting up and inserting data in PouchDb on Ionic 2 -
hi guys im new ionic 2,
but know js/ts , fun stuff already. want use pouchdb in ionic app here home.ts file:
import { component } '@angular/core'; import * pouchdb 'pouchdb'; import cordovasqliteplugin 'pouchdb-adapter-cordova-sqlite'; @component({ selector: 'page-home', templateurl: 'home.html' }) export class homepage { } pouchdb.plugin(cordovasqliteplugin); var db = new pouchdb('test', { adapter: 'cordova-sqlite' }); function setdata(data) { var todo = { title: data, completed: false }; db.post(todo, function callback(err, result) { if (!err) { console.log('successfully posted todo!'); } }); } function getdata() { console.log(db.alldocs); }
here first problem var db = new pouchdb....
is no fuction when put in on startup function error because "setdata" function doesnt know "db" is. how can fix that? , importing stuff right?
next question have import stuff in app.module.ts file too? need provider?
import { ngmodule, errorhandler } '@angular/core'; import { browsermodule } '@angular/platform-browser'; import { ionicapp, ionicmodule, ionicerrorhandler } 'ionic-angular'; import { myapp } './app.component'; import { aboutpage } '../pages/about/about'; import { contactpage } '../pages/contact/contact'; import { homepage } '../pages/home/home'; import { tabspage } '../pages/tabs/tabs'; import { statusbar } '@ionic-native/status-bar'; import { splashscreen } '@ionic-native/splash-screen'; @ngmodule({ declarations: [ myapp, aboutpage, contactpage, homepage, tabspage ], imports: [ browsermodule, ionicmodule.forroot(myapp), ], bootstrap: [ionicapp], entrycomponents: [ myapp, aboutpage, contactpage, homepage, tabspage ], providers: [ statusbar, splashscreen, {provide: errorhandler, useclass: ionicerrorhandler}] }) export class appmodule {}
i think thats now. thank help
first, need install sqlite provider. here tutorial setting pouchdb in ionic using sqlite database.
https://gonehybrid.com/how-to-use-pouchdb-sqlite-for-local-storage-in-ionic-2/
if need more help, comment , improve answer.
Comments
Post a Comment