I initially used the example from Heroes as a guide, but with a different API method - mine is post instead of get.
This is the Interface I have:
export interface IContasMae {
codEstab: string;
codProduto: string;
desContaMae: string;
codRep: number;
numQuantidade: number;
numValVenda: number;
numValMedio: number;}
In the service, I've implemented the following method:
getContasMae() : Observable<IContasMae[]> {
if (this.getUser()) {
return this.http.post<IContasMae[]>(`${environment.api_url}/getContasMae`,'');
}
}
The property 'contasMae' in the component is defined as:
export class PanelDashboardComponent implements OnInit {
public contasMae: IContasMae[];
(Referencing the above interface)
To call the method in the component, it's done like this:
this.service.getContasMae().subscribe(contasMae =>
{
console.log('Observable:',contasMae);
this.contasMae = contasMae;
});
console.log('Result:',this.contasMae);
}
The console log for the Observable shows the data retrieved, but when checking 'this.contasMae', it returns undefined.
What could be causing this issue? How can I store the result in 'this.contasMae' successfully?
If anyone has any ideas or solutions, your help would be greatly appreciated!
Thank you in advance.