Hi to all again
I followed the vks_gautam1 suggestion by creating a provider which looks like
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';
const DATABASE_NAME: string = 'signalsDatabase.db';
@Injectable()
export class DatabaseProvider {
public db : SQLiteObject;
constructor(public http: Http, public sqlite: SQLite) {
}
public createDatabase() {
this.sqlite.create({name: DATABASE_NAME, location: 'default'})
.then((db: SQLiteObject) => {
this.db = db;
})
.catch(e => alert(e));
}
//création de la table `SIGNALEMENTS`
public createTable() {
this.db.executeSql('CREATE TABLE IF NOT EXISTS `SIGNALEMENTS` ( `idSIGNALEMENTS` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, `signalement` TEXT NOT NULL, `date` TEXT NOT NULL, `commentaires` TEXT NOT NULL, `longit` INTEGER NOT NULL, `latit` INTEGER NOT NULL, `image` BLOB )', {})
.then(() => alert('SQL query executed'))
.catch(e => alert(e));
}
public insertInto(signal_details){
let insert_query = 'INSERT INTO `SIGNALEMENTS` (signalement, date, commentaires, longit, latit) VALUES (?, ?, ?, ?, ?)';
this.db.executeSql(insert_query, [signal_details.signalement,
signal_details.date,
signal_details.commentaires,
signal_details.longit,
signal_details.latit
])
.then((data) => alert("Data insertion executed"))
.catch((e) => alert(e));
}
public getSignalements(){
return this.db.executeSql('SELECT * FROM SIGNALEMENTS', []);
}
//méthode de suppression de la table
public dropDatabase(){
this.sqlite.deleteDatabase({name: DATABASE_NAME,
location: 'default'
})
}
}
then, I import this database provider in my ListePage like this
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Http } from '@angular/http';
//importation du provider database caractérisant le DAO de la base de données
import { DatabaseProvider } from '../../providers/database/database';
@IonicPage()
@Component({
selector: 'page-liste',
templateUrl: 'liste.html',
})
export class ListePage {
signal = {};
signalsTab = [];
constructor(public navCtrl: NavController, public navParams: NavParams, public dbService: DatabaseProvider) {
let temp = navParams.get('signalement');
if (temp!=undefined) {
this.signal = ({signalement: navParams.get('signalement'),
date: navParams.get('date'),
commentaires: navParams.get('commentaires'),
longit: navParams.get('longit'),
latit: navParams.get('latit')
});
this.dbService.insertInto(this.signal);
}
Promise.all([this.dbService.getSignalements()]).then((data) => {
this.signalsTab.push(data);
});
}.......
The Database creation, InsertInto and getData working very well but I tried to display my Tab objects (signalsTab) in my without success. How could I do this ?
Thanks in advance and really sorry for my poor english level