import { Component, OnInit, Output, EventEmitter } from '@angular/core'; import { CartService } from 'app/services/cart.service'; import { SharedService } from 'app/shared/shared.service'; import { ActivatedRoute } from '@angular/router'; import { Customer } from 'app/shared/modal/customer'; import { Cart } from 'app/shared/modal/cart'; @Component({ selector: 'public-cart', templateUrl: './cart.component.html', styleUrls: ['./cart.component.css'], }) export class PublicCartComponent implements OnInit { storeId: number; customer: Customer; orderNumberFromURL: number; cart: Cart; orderStatusItems: any[]; // Setting the output prop to send data to another component @Output() cartInfoEv = new EventEmitter(); constructor(private cartService: CartService, private sharedService: SharedService, private activatedRoute: ActivatedRoute) { } ngOnInit() { this.sharedService.storeId.subscribe((val: number) => { this.storeId = val; }); // Reading OrderID from URL this.activatedRoute.queryParams.subscribe(params => { this.orderNumberFromURL = parseInt(params.orderId.substring(2)); }); this.sharedService.showSpinner(true); // spinner this.cartService.getCartSummary(this.storeId, this.orderNumberFromURL).subscribe(cartData => { this.sharedService.showSpinner(false); // spinner this.cart = Object.assign({}, cartData); this.cartInfoEv.emit(this.cart); // Emitting the cart data to the output prop }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } }