Here, x is not being able to access the properties of ShoppingCart the error it shows is Property item does not exist on type {} I dont know where is mistake i have made which i am not being able to identified
shopping-cart.service.ts
async getCart(): Promise<Observable<ShoppingCart>> {
let cartId = await this.getOrCreateCartId();
return this.db.object('/shopping-carts/' + cartId)
.valueChanges()
.pipe(
map(x => new ShoppingCart(x.items))
);
}
**ShoppingCart.ts**
import { Product } from './product';
import { ShoppingCartItem } from "./shopping-cart-item";
export class ShoppingCart {
items: ShoppingCartItem[] = [];
constructor(private itemsMap: { [productId: string]: ShoppingCartItem }) {
this.itemsMap = itemsMap || {};
for (let productId in itemsMap) {
//we explicitly map each of the object to shoppingCart object
let item = itemsMap[productId];
this.items.push(new ShoppingCartItem({
// title: item.title,
// imageUrl: item.imageUrl,
// price: item.price,
...item,
key: productId
}));
}
}
If you still have that problem then this may help...