import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core'; import { SharedService } from 'app/shared/shared.service'; import { ActivatedRoute } from '@angular/router'; import { CartService } from 'app/services/cart.service'; import { IPayment } from 'app/shared/modal/common'; @Component({ selector: 'public-payment', templateUrl: './payment.component.html', styleUrls: ['./payment.component.css'] }) export class PublicPaymentComponent implements OnInit { private storeId: number; private orderNumberFromURL: number; paymentInfo: IPayment; // Setting the output prop to send data to another component @Output() paymentInfoEv = new EventEmitter(); constructor( private sharedService: SharedService, private cartService: CartService, 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.getCartPayment(this.storeId, this.orderNumberFromURL).subscribe(paymentData => { this.sharedService.showSpinner(false); // spinner this.paymentInfo = paymentData; this.paymentInfoEv.emit(this.paymentInfo); // Emitting the payment info to the output prop }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); console.error('error=>' + error); }); } }