In my application, until now, I retrieved data that have to be shown into a table from a mocked array of objects (where each object represents a row of my table).
Originally I simply had something like this into my component TypeScript code:
orders: any[];
then into my ngOnInit() method I done:
this.ordersService.getAllOrders().then(orders => {
this.orders = orders;
console.log("RETRIEVED ORDERS: ", orders);
this.loading = false;
});
where the getAllOrders() method of my service simply retrieved data (the array) from a JSON file:
getAllOrders() {
return this.http.get<any>('assets/json_mock/ordini.json', {responseType: 'json'})
.toPromise()
.then(res => res.data)
.then(data => { return data; });
}
It works fine.
Now I am trying to retrieve this array of objects from FireStore database and I have some problem.
I have done in this way.
Into the ngOnInit() of my component class now I have:
this.ordersService.getAllOrders().subscribe(ordersList => {
console.log("RETRIEVED ordersList: ", ordersList);
this.orders = ordersList;
console.log("RETRIEVED ORDERS: ", this.orders);
this.loading = false;
});
Then into the service class the getAllOrders() is changed in this way:
getAllOrders(): Observable<any[]> {
this.ordersList = this.db.collection('Orders').snapshotChanges();
return this.ordersList;
}
It partially works because it semmes that retrieve something from FireStore (the connection works fine) and I think also my "query".
The problem is that into the subscribe() method of my component, these lines:
this.ordersService.getAllOrders().subscribe(ordersList => {
console.log("RETRIEVED ordersList: ", ordersList);
this.orders = ordersList;
console.log("RETRIEVED ORDERS: ", this.orders);
this.loading = false;
});
it print in the Chrome console:
So I think that I have to extract my array in some way from this object. What am I missing? How can I do it?
