1
I am studying Angular with IONIC and I have some questions about function execution and I would like to know if someone has how to explain me: I have that function:
public faltas: number;
public selectFalta(): any{
//this.faltas = 11;
this.databaseService.getDB()
.then((db:SQLiteObject) =>{
let sql = "select count(*) as total from agenda where vch_situacao = '1'";
let data: any[];
console.log("Agenda_DAO - selectFalta - SQL: "+sql);
db.executeSql(sql,data).then((data) =>{
if(data.rows.length > 0){
let temp = data.rows.item(0);
this.faltas = temp.total;
//this.faltas = 13;
return this.faltas;
console.log("Agenda_DAO - selectFalta: Encontrou Faltas: "+this.faltas);
}else{
console.log("Agenda_DAO - selectFalta: Não encontrou faltas");
}
}).catch(e => {
console.log("Erro Select: No Exec "+e);
});
}).catch(e=>{
console.error("Erro Select: Sem DB "+e);
});
console.log("Agenda_DAO - Faltas: "+this.faltas);
//this.faltas = 13;
return this.faltas;
}
The problem is that on the call:
if(data.rows.length > 0){
let temp = data.rows.item(0);
this.faltas = temp.total;
he finds the value and assigns, (console.log("Agenda_DAO - selectFalta: Encontrou Faltas: "+this.faltas); aqui mostra o valor retornado
) except that when I call this value in a variable on another page, it comes null. Ex:
let flt = this.Agenda_DAO.selectFalta();
//on other system pages does not return nd
The function, does not stop processing in the 1st Return, does it continue running? It seems that the execution inside the "then" has no effect, it Zera the variable this.faltas after q leaves then? How to return this value and access another page?
I come from development in PHP and I have many difficulties in these aspects of function execution returns.