У меня есть компонент-контейнер (называемый file-container
) с кнопкой ngbPopover
. Содержимое всплывающего окна — еще один компонент. (Используется для выбора файла для загрузки).
<button type="button"
class="btn btn-secondary popover-btn"
placement="top"
[ngbPopover]="popContent"
popoverTitle="Click to add files - will be a label"
container="body"
trigger="manual"
#popover="ngbPopover"
(click)="populateDropdownList()">
Click to add files
</button>
<template #popContent>
<app-file-uploader [maxFiles]="maxFiles"
[fileNames]="fileNames"
(onUpload)="uploadEboxAttachment($event)">
</app-file-uploader>
</template>
Загрузчик файла приложения создает событие при нажатии кнопки Upload
. Компонент контейнера обрабатывает фактическую загрузку файла на сервер.
Я хочу, чтобы код file-container
TypeScript также обрабатывал закрытие всплывающего окна. Чтобы после получения ответа от сервера всплывающее окно закрывалось.
Как я могу передать всплывающее окно в файл .ts
, чтобы я мог вызвать на нем .close()
?
РЕДАКТИРОВАНИЕ кода:
createEboxAttachment(event):Observable<any>{
return new Observable<any>(observer => {
this.jsConnection.sobject("EBOX_Attachment__c").create({Name : event.selectedFile, Tender_Reply__c : this.tender.Reply.Id})
.then(ret => observer.next(ret))
.catch(error => observer.error(error));
});
}
createAttachment(base64data, event, ret):Observable<any>{
let name = event.selectedFile == this.$Label.EBOX_Other ? event.file.name : event.selectedFile;
return new Observable<any>(observer => {
this.jsConnection.sobject("Attachment").create({
ParentId : ret.id,
Name : name,
Body : base64data.substring(base64data.lastIndexOf('base64,')+7),
ContentType : event.file.type
})
.then(ret => observer.next(ret))
.catch(error => observer.error(error));
});
}
sendAttachToSF(base64data, event){
this.createEboxAttachment(event).subscribe(
ret => {
this.createAttachment(base64data, event, ret).subscribe(att => {
this.fileUploaded(att, event);
});
},
error => this.toastr.error(error)
);
}
uploadEboxAttachment(event){
if (!this.jsConnection){
this.jsConnection = window["jsConnection"];
}
let reader: FileReader = new FileReader();
reader.onloadend = (e) => (this.sendAttachToSF(reader.result, event));
reader.readAsDataURL(event.file);
}
fileUploaded(result, event){
// this.popover.close(); would like to close popover here.
this.onFileUploaded.emit(att); //emit event to parent component. works
}
close()
после того, как получу подтверждение от моего Observable (я знаю, что эта часть работает, потому что тогда я делаю другие вещи). - person AvailableName   schedule 27.04.2017