问题
I create provider to insert , select , delete , update data in sqlite
this my code in database.service.ts to get data
getData(){
return this.sqlite.create({
name: 'data.db',
location: 'default'
})
.then((db: SQLiteObject) => {
db.executeSql('select * from downloaded order by ID', {})
.then(res => {
for(let i = 0;i < res.row.length; i++){
this.data.push({
id: res.row.item(i).id,
name: res.row.item(i).name,
url: res.row.item(i).URL
})
}
return this.data;
}).catch(e => {
console.log(e);
});
})
}
and this my code in list.ts to receive the data
getData(){
this.data = this.DB.getData();
}
but no values return
回答1:
You must publish an event with your data and listen your event in where you wait for data.
Because:
this.sqlite.create({ name: 'data.db', location: 'default' }) .then()
Is async call and dosnt return value. You should do like this:
this.events.publish('getData', dataRows);
And listen to event in where you want:
events.subscribe('getData', (data) => {
//Do somethings
});
来源:https://stackoverflow.com/questions/50667665/ionic-3-sqlite-not-return-value