import { Component, OnInit } from '@angular/core'; import { DynamicDialogRef, DynamicDialogConfig, DialogService, MessageService } from 'primeng/api'; import { ContactService } from '../../../shared/service/contact.service'; @Component({ selector: 'app-contact-import', templateUrl: './contact-import.component.html', styleUrls: ['./contact-import.component.css'], providers: [DialogService, MessageService] }) export class ContactImportComponent implements OnInit { // Upload file ulpoadFile: string; // File Id fileId: number; constructor( public contactImportComponent: DynamicDialogRef, public config: DynamicDialogConfig, public dialogService: DialogService, private messageService: MessageService, private contactService: ContactService) { } ngOnInit() { } // Upload Contacts Upload(event: any): void { const files = event.target.files; if (files) { for (const file of files) { const reader = new FileReader(); reader.onload = (e: any) => { }; reader.readAsDataURL(file); } } this.ulpoadFile = event.target.files[0]; // console.log(this.ulpoadFile); } // Update Update() { if (this.ulpoadFile !== null && this.ulpoadFile !== undefined) { const frmData = new FormData(); frmData.append('fileUpload', this.ulpoadFile); this.contactService.UpdateContact(frmData).subscribe( data => { // this.fileId = +data; this.Cancel(); } ); } } // Cancel Cancel() { //this.dialogService.dialogComponentRef.instance.close(); this.contactImportComponent.close(); } }