#how to get data from API in angular

8 messages · Page 1 of 1 (latest)

cedar hatch
#

You got to show your code and explain precisely the problem you're encountering.

dense pumice
#

See #how-to-get-help

somber perch
#

addToCart(product : list){
if (product?.variant_list[0]?.price) {
let newCartItem: cartItem = Object.assign({}, {...product}, {quantity: 1, price: parseInt(product.variant_list[0].price)});
console.log('newitem', newCartItem)
let indexOfExistingItem = -1;
this.cartList.forEach((item: cartItem, i:number) => {
if (newCartItem.name === item.name) {
indexOfExistingItem = i
}
})

  if (indexOfExistingItem > -1) {
    let currentQuantity = this.cartList[indexOfExistingItem]?.quantity
    let updatedNewItem = Object.assign(newCartItem, {quantity: currentQuantity + 1});
    this.cartList[indexOfExistingItem] = updatedNewItem
  } else {
    this.cartList.push(newCartItem)
  }
  console.log(this.cartList)
}

}

cedar hatch
#

Please look at the channel suggested by jbnizet.

somber perch
cedar hatch
#

As you like.
There's no problem in keeping this one.

dense pumice
#

Our suggestion is not to post your question elsewhere. Our suggestion is to ask a good question, by following the guidelines explained in #how-to-get-help . You need to read and understand that.

fast roost