I'm currently attempting to convert an observable array into a regular array and then return the new array using the spread operator within the `get` function.
I initially tried manually converting the observable array before subscribing with the map operator, but I couldn't find a solution. It still remains as an Observable of type void. How can I convert this observable array into a usable array so that I can utilize the spread operator in `get orders()` where I need to return an array type for a calculation?
//in grid.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Order } from '../order/order.model';
@Injectable({
providedIn: 'root'
})
export class OrderGridService{
constructor(private http: HttpClient){}
private _orders: Order[];
getAllOrder(): Observable<Order[]> {
return this.http.get<Order[]>(this._orderURL + "/" +
this.userID + "/" + this.currentUservalueToken);
};
get orders(): Order[] {
return [...this._orders];
}
}
I need to assign the response of the html request performed in the function `getAllOrder()` to the variable `_orders`. However, it is returning an Observable of `Order[]` instead of an array. This prevents me from simply returning `[...this._orders]`. I hope my issue is clear.. Any advice would be greatly appreciated! Thank you.