I am trying to get the total price from the database and showing it on my website. But on my website it is showing me [object Object]. I tried alot of different things, including changing any to string or to Observable string. I am new to angular, so i dont really know how to solve this right now. Thanks in advance!
order.service.ts:
getTotalPrice(userId: Pick<User, 'id'>): any {
return this.http
.get(`${this.url}/price/${userId}`, { responseType: 'json' });
}
shoppingcart.ts:
total: any;
ngOnInit(): void {
this.total = this.getTotalPrice(this.userId);
}
getTotalPrice(userId: Pick<User, 'id'>): any {
return this.orderService.getTotalPrice(userId);
}
Html:
<h1> {{total | async}} </h1>
when i try this code on shoppingcart.ts:
ngOnInit(): void {
this.total.subscribe({
next(num) {console.log(num); }
});
}
it is showing me this on the console.
[{…}]
0: {Totalprice: "134.94"}
length: 1
__proto__: Array(0)