I’m new to ionic2 and I’m having some issue creating a DB service for SQLite.
So I have the following service that will open a connection to my database
dbservice.ts
import { Injectable } from '@angular/core';
import { Platform } from 'ionic-angular';
import { SQLite } from 'ionic-native';
@Injectable()
export class Dbservice {
db: SQLite;
constructor(public platform: Platform) {
this.platform.ready().then(() => {
this.db = new SQLite();
this.db.openDatabase({name:'setup.db',location:'default'});
});
}
}
On my app.comonents.ts I have the following code.
import { Component, ViewChild } from '@angular/core';
import { Nav, Platform } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { Dbservice } from '../providers/dbservice';
@Component({
templateUrl: 'app.html',
providers: [Dbservice]
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage: any = Home;
pages: Array<{title: string, component: any}>;
constructor(public platform: Platform, private dbService: Dbservice) {
this.initializeApp();
this.pages = [
{title: 'Home', component: Home}
];
}
initializeApp() {
this.platform.ready().then(() => {
StatusBar.styleDefault();
this.dbService.db.executeSql('CREATE TABLE IF NOT........ ',{}).then(() => {
console.log('HERE');
}, function(error){
console.log(error);
});
Splashscreen.hide();
});
}
openPage(page) {
this.nav.setRoot(page.component);
}
}
I get an error saying it cannot ready property of ‘executeSql’ of undefined.
Thanks,
Ennio