【发布时间】:2017-01-10 00:08:27
【问题描述】:
我有这个购物车组件,用于从后端获取购物车数据。
import { Component, OnInit } from '@angular/core';
import { CartService } from './cart.service';
@Component({
selector: 'cart',
templateUrl: './cart.component.html',
styleUrls: ['./cart.component.css']
})
export class CartComponent implements OnInit{
carts: any;
cartItems: any;
totalPrice: Number;
constructor(private _cartService: CartService){};
ngOnInit(){
this.getItems();
}
getItems(){
this._cartService.getCartItems(localStorage.getItem('currentUserId'))
.subscribe((cart) => {
this.cartItems = cart.products;
this.totalPrice = cart.totalPrice;
this.carts = cart;
console.log(this.carts)
},
(err) => console.log(err));
}
}
这是我的对象值。
我将所有产品放入我的组件上显示的 cartItems 中,并使用 *ngFor 在我的模板中循环它
<tbody *ngFor="let cartItem of cartItems">
这是结果
现在我想更新一件商品的数量,按下删除按钮旁边的刷新按钮,然后它只会将我按下刷新按钮的产品详细信息发送到我的后端。
有人可以帮我实现它吗?
【问题讨论】:
-
什么不起作用?
-
我需要从数组中获取对象值。例如产品 Fast,我会将数量更新为 10,如何从 *ngFor 数组中获取?
标签: angular