I have a function that makes a query to sqlite, in a global variable I save the result, but the variable is shown undefined.
public lng:any;
getLanguage(){
this.sqlite.create({
name: ‘wconline.db’,
location: ‘default’
}).then((db: SQLiteObject) => {
db.executeSql(‘CREATE TABLE IF NOT EXISTS language(id INTEGER PRIMARY KEY, language TEXT)’, {})
.then(res => console.log(‘Executed SQL’))
.catch(e => console.log(e));
db.executeSql('SELECT language FROM language WHERE id=1', {})
.then(res => {
this.lng = res.rows.item(0).language;
})
.catch(e => console.log(e));
}).catch(e => console.log(e))
}
ionViewDidLoad() {
this.getLanguage();
}
ionViewWillEnter() {
this.getLanguage();
}
Thanks in advanace!