import { Component , OnInit } from '@angular/core' ; import { ActivatedRoute } from '@angular/router' ; import { PrintService } from '../print.service' ; @ Component ( { selector : 'app-invoice' , templateUrl : './invoice.component.html' , styleUrls : [ './invoice.component.css' ] } ) export class InvoiceComponent implements OnInit { invoiceIds : string [ ] ; invoiceDetails : Promise < any > [ ] ; constructor ( route , private printService ) { this . invoiceIds = route . snapshot . params [ 'invoiceIds' ] . split ( ',' ) ; } ngOnInit ( ) { this . invoiceDetails = this . invoiceIds . map ( id => this . getInvoiceDetails ( id ) ) ; Promise . all ( this . invoiceDetails ) . then ( ( ) => this . printService . onDataReady ( ) ) ; } getInvoiceDetails ( invoiceId ) { const amount = Math . floor ( ( Math . random ( ) * 100 ) ) ; return new Promise ( resolve => setTimeout ( ( ) => resolve ( { amount } ) , 1000 ) ) ; } }