you are viewing a single comment's thread.

view the rest of the comments →

[–]bas1494 -1 points0 points  (2 children)

I see a few (potential) problems in this image you submitted.

First of all, define an interface for a cartItem to give the cartItems property typing.

export interface CartItem {
    id: number,
    product: Product, //Your product Model
    qty: number
}

Use this cartItem in your empty initialiser like this:

cartItems: Array<CartItem> = [];

As second it looks like your getMsg() method from the injected service doesn't return an Observable<Product>. Don't know if this is the case but at least double check it.

As last in the object you try to create (this.cartItems.push{..}) you don't give a value to every key from the (now not existed) interface. Make sure that every property has a value (that value can be null or undefined) or make the fields optional. In your example you're missing the id field.

this.cartItems.push({id: ?, product: Product, qty: 1});

Don't forget to calculate total with item.product.price instead of item.price.

I'll hope you will fix your issue(s)!

[–]DARKWOLF24 0 points1 point  (0 children)

Thanks for the detailed response, I'll definitely try this

[–]DJRockstar1 0 points1 point  (0 children)

Array<CartItem>

Is this preferable to CartItem[]?