Ionic View and SQLLite


#1

I’m using Ionic 2 with the SQLLite plugin, i noticed this doesn’t work on the browser using ionic serve.
But i saw here: https://docs.ionic.io/tools/view/ that the plugin is supported.

Now when i try it out on the Ionic View app on my iPhone i get the same message as in the browser: ReferenceError: sqlitePlugin is not defined

What am i doing wrong?

My Code:
constructor(public http: Http, public alertCtrl: AlertController) {
this.db = new SQLite();
this.db.openDatabase({name: “data.db”, location: “default”}).then(() => {
//this.refresh();
this.showalert(“Success”, “DB connection”);
}, (error) => {
this.showalert(“Construct Error”, error);
});
}


#2

I think you should do that on platform ready;

constructor(public http: Http, public alertCtrl: AlertController, public platform: Platform) {
  platform.ready().then(() => {
    this.db = new SQLite();
    this.db.openDatabase({name: "data.db", location: "default"}).then(() => {
    //this.refresh();
    this.showalert("Success", "DB connection");
    }, (error) => {
        this.showalert("Construct Error", error);
    });
  });
}

Of course you must import “Platform” from “ionic-angular”.


#4

Is there any way to use SQLite and combine it with browser support?
I’ve seen some methods like: if (this.platform.is(‘cordova’)) { use sqlite plugin } else { use browser }

But i can’t really figure out how i can do this.