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