[英]adding product to header shopping cart in angular 6
we are using angular 6 我们正在使用角度6
I am not able to add the product to the cart's header (header components) but it's working perfectly in cart page (cart components) 我无法将产品添加到购物车的标题(标题组件),但在购物车页面(购物车组件)中运行良好
I am getting data from services (cart.services). 我正在从服务(cart.services)获取数据。 Cart components got the data but header components doesn't. 购物车组件获取了数据,但标头组件没有。 why ? 为什么呢?
`public cartItems public cartItems : BehaviorSubject<CartItem[]> = new
BehaviorSubject([]);
public observer : Subscriber<{}>;
public product : CartItem[] = [];
constructor(private toastrService: ToastrService) {
this.cartItems.subscribe(products => this.product = products);
}`
`public getItems(): Observable<CartItem[]> {
const itemsStream = new Observable(observer => {
observer.next(this.product);
observer.complete();
});
return <Observable<CartItem[]>>itemsStream;
}`
**both component code (header and cart)**
`this.cartService.getItems().subscribe(shoppingCartItems => this.shoppingCartItems = shoppingCartItems);`
this.cartItems.subscribe(products => this.product = products);
我看不到这指向实际的服务调用以检索项目的位置
public cartItems : BehaviorSubject<CartItem[]> = new BehaviorSubject([]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.