Hi,
I am new for ionic and i am creating mobile app using cordova +anjular+ionic .For that i using sqllite to connecting database during this time "CORODOVA not available" this error showing pls help me
below my code:
Database.ts
import { Injectable } from ‘@angular/core’;
import { Platform } from ‘ionic-angular’;
import { SQLite, SQLiteObject } from ‘@ionic-native/sqlite’;
import { SQLitePorter } from ‘@ionic-native/sqlite-porter’;
import { Http } from ‘@angular/http’;
import ‘rxjs/add/operator/map’;
import { BehaviorSubject } from ‘rxjs/Rx’;
import { Storage } from ‘@ionic/storage’;
/*
Generated class for the DatabaseProvider provider.
See https://angular.io/guide/dependency-injection for more info on providers
and Angular DI.
*/
@Injectable()
export class DatabaseProvider {
ready: Promise;
database: SQLiteObject;
private databaseReady: BehaviorSubject;
constructor(public sqlitePorter: SQLitePorter, private storage: Storage, private sqlite: SQLite, private platform: Platform, private http: Http) {
this.databaseReady = new BehaviorSubject(false);
this.platform.ready().then(() => {
this.sqlite.create({
name: ‘developers.db’,
location: ‘default’
})
.then((db: SQLiteObject) => {
this.database = db;
this.storage.get(‘database_filled’).then(val => {
if (val) {
this.databaseReady.next(true);
} else {
this.fillDatabase();
}
});
});
});
}
fillDatabase() {
this.http.get(‘assets/icon/main.sql’)
.map(res => res.text())
.subscribe(sql => {
this.sqlitePorter.importSqlToDb(this.database, sql)
.then(data => {
this.databaseReady.next(true);
this.storage.set(‘database_filled’, true);
})
.catch(e => console.error(e));
});
}
addDeveloper(name, skill, years) {
let data = [name, skill, years]
return this.database.executeSql(“INSERT INTO developer (name, skill, yearsOfExperience) VALUES (?, ?, ?)”, data).then(data => {
return data;
}, err => {
console.log('Error: ', err);
return err;
});
}
getAllDevelopers() {
return this.database.executeSql(“SELECT * FROM developer”, []).then((data) => {
let developers = [];
if (data.rows.length > 0) {
for (var i = 0; i < data.rows.length; i++) {
developers.push({ name: data.rows.item(i).name, skill: data.rows.item(i).skill, yearsOfExperience: data.rows.item(i).yearsOfExperience });
}
}
return developers;
}, err => {
console.log('Error: ', err);
return [];
});
}
getDatabaseState() {
return this.databaseReady.asObservable();
}
}
Home.ts
export class HomePage {
developer = {};
developers = [];
constructor(public navCtrl: NavController,public app:App, private databaseprovider: DatabaseProvider, private platform: Platform) {
// this.databaseprovider.getDatabaseState().subscribe(rdy => {
// if (rdy) {
// this.loadDeveloperData();
// }
// })
}
loadDeveloperData() {
this.databaseprovider.getAllDevelopers().then(data => {
this.developers = data;
})
}
addDeveloper() {
this.databaseprovider.addDeveloper(this.developer[‘name’], this.developer[‘skill’], parseInt(this.developer[‘yearsOfExperience’]))
.then(data => {
this.loadDeveloperData();
});
this.developer = {};
}
logout(){
// Remove API token
const root = this.app.getRootNav();
root.popToRoot();
}
My error