0
I’m trying to make an appointment at firebase with Ionic and I’m having the following mistake:
The source is like this:
import { Injectable } from '@angular/core';
import firebase from 'firebase' import { Pedidomodel } from '.. /model/request.model'
@Injectable() export class Pedidoservice{
//DATA_URL = firebase.storage.StringFormat.DATA_URL
pedidos:any
pedidosPes:any
constructor(){
// Initialize Firebase
const config = {
apiKey: "xx",
authDomain: "xx",
databaseURL: "xx",
projectId: "xx",
storageBucket: "xxx",
messagingSenderId: "xx"
};
firebase.initializeApp(config);
let ref = firebase.database().ref('statuspedido');//statuspedido
this.pedidos = new Array();
ref.on('value', (dataSnapshot) =>{
let items = dataSnapshot.val();
for(let dados in items){
this.pedidos.push(
new PedidoModel(
items[dados].dataEmissao,
items[dados].dataAtualizacao,
items[dados].vendedor,
items[dados].frete,
items[dados].transportadora,
items[dados].status)
)
}
})
}
loadDados(){
// console.log(this.pedidos);
return this.pedidos;
}
getItems(filtro: string){
this.pedidosPes = new Array();
let query = firebase.database().ref('statuspedido').orderByChild('status').startAt(filtro);
query.on('child_added', function(snap) {
let ped = snap.val();
this.pedidosPes.push(
new PedidoModel(
ped.dataEmissao,
ped.dataAtualizacao,
ped.vendedor,
ped.frete,
ped.transportadora,
ped.status)
)
console.log(ped.dataAtualizacao, ped.dataEmissao);
});
return this.pedidosPes;
}
}
This seems to be more a problem of asynchrony
– Rosário Pereira Fernandes