I am seeking clarity on a specific issue that seems to be quite common after researching similar questions. I am currently learning by studying and attempting to replicate another person's code. One of the methods in an injectable returns a promise, and I am trying to access the data within this promise from a different method where it has been injected.
Here is the code snippet I am referring to:
getLists(){
return this.isReady()
.then(()=>{
return this.database.executeSql("SELECT * from list", [])
.then((data)=>{
let lists = [];
for(let i=0; i<data.rows.length; i++){
lists.push(data.rows.item(i));
console.log(i);
}
return lists;
})
})}
And here is my attempt at implementing something similar, which is not functioning correctly due to mismatched types (string[] does not match Promise)
`
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { DatabaseService } from '../../app/database-service';
@Component({
selector: 'page-home',
templateUrl: 'home.html',
providers:[DatabaseService],
})
export class HomePage {
listas:string[];
constructor(public navCtrl: NavController, private service:DatabaseService ) {
}
getLists(){
this.listas=this.service.getLists();
}
getList(){
this.service.getList(0);
}
addList(){
this.service.addList("Shazam");
}
deleteList(){
this.service.deleteList(0);
}
}`
Thank you for your understanding and patience as I navigate through this challenge.