import { Component, OnInit, OnDestroy } from '@angular/core'; import { AuthenticationService } from '../../../_services/authentication.service'; import { ProfileService } from '../profile.service'; import { RootService } from '../../../_services/root.service'; import { Subscription } from 'rxjs/Subscription'; import { ActivatedRoute } from '@angular/router'; import { Profile } from '../profile.class'; @Component({ selector: 'app-view', templateUrl: './view.component.html', styleUrls: ['./view.component.scss'] }) export class ViewComponent implements OnInit, OnDestroy { private subscription: Subscription; public cnic: string = '0'; public profile: Profile; constructor(private _rootService: RootService, private _profileService: ProfileService, private _authenticationService: AuthenticationService, private route: ActivatedRoute) { } ngOnInit() { this.fetchParams(); } private fetchParams() { this.subscription = this.route.params.subscribe( (params: any) => { if (params.hasOwnProperty('cnic')) { this.cnic = params['cnic']; this.fetchData(this.cnic); } } ); } private fetchData(cnic) { this._profileService.getProfile(cnic).subscribe( res => { this.profile = res as Profile; } ); } public dashifyCNIC(cnic: string) { return cnic[0] + cnic[1] + cnic[2] + cnic[3] + cnic[4] + '-' + cnic[5] + cnic[6] + cnic[7] + cnic[8] + cnic[9] + cnic[10] + cnic[11] + '-' + cnic[12]; } printProfile() { let html = document.getElementById('profileInfo').innerHTML; var mywindow = window.open('', 'PRINT', 'height=600,width=900'); if (mywindow) { mywindow.document.write(` Profile`); mywindow.document.write(''); //mywindow.document.write(''); mywindow.document.write(html); mywindow.document.write(` `); mywindow.document.write(''); mywindow.document.close(); // necessary for IE >= 10 mywindow.focus(); // necessary for IE >= 10*/ mywindow.print(); mywindow.close(); } } ngOnDestroy() { this.subscription.unsubscribe(); } }