-1
I created a service to hit my API and return all orders according to certain type params.
When I try to assign the return to my Component, it does not return me an array of results, it returns me a Subscriber.
Service
baseUrl = 'http://localhost:3001';
constructor(private http: HttpClient) { }
getPedidos = (tipo: Pedidos): Observable<any> => this.http.get(`${baseUrl}/pedidos?tipo=${tipo}`);
Component ts
ngOnInit() {
this.pratosPrincipais = this.getPedidos(1);
}
private getPedidos = (tipo) =>
this.pedidoService.getPedidos(tipo)
.subscribe(pedido => pedido)
When assigning the variable, this is the value assigned:
Right after that, I pass the value via Input to another component.
<app-expansion-panel title="Prato Principal" [data]=pratosPrincipais></app-expansion-panel>
Component Expansion panel ts
@Input() data;
I tried to subscribe to date, but it shows error which is not a function. I tested the api and it works normally.
What am I forgetting?
the final error is in your bind [date]="silverPrincipais"
– ruansenadev
I tried it the way you told me, but it returned me [Object Object]
– Desenv Junior
that’s not the answer?
– ruansenadev
should return me an array of objects
– Desenv Junior
the object array is the [Object Object], it must be discontinued within the subscribe function before associating to the silversPrincipais
– ruansenadev