В моем angular
приложении я открываю динамическое c диалоговое окно, подобное этому в sidebar.component.ts
const ref = this.dialogService.open(ConfirmDialogComponent, {
width: '30%',
styleClass: 'small-heading-dialog',
showHeader: false,
data: {
title : 'Save changes?',
message : '',
type : 'changes',
button: {
success: { title: 'Save' },
discard : { title : 'Discard' },
cancel: { title: 'Cancel' }
}
}
});
ref.onClose.subscribe(({ isSuccess, data }) => {
// const obj = data.data;
if (isSuccess) {
console.log('in success');
this.isCustomerSaveChange = true;
this.dataService.sendData(this.dataService
.typePassData('update-customer', true));
// this.dRef.close()
}else{
this.isCustomerSaveChange = false;
}
});
Вот мой модальный dialog.component.html
<div class="confirm-diloag">
<div class="confirm-dialog-header flex-between-center">
<h4 class="confirm-dialog-heading mb-0">{{data?.title}}</h4>
<i class="fal fa-times pointer" (click)="closeDialog(false)"></i>
</div>
<div class="confirm-dialog-content">
{{data?.message}}
</div>
<div class="confirm-dialog-footer flex-end-center">
<button *ngIf="data?.button?.cancel?.title" (click)="closeDialog(false)" class="btn-light mr-2" [ngStyle]="{
'background-color': data?.button?.cancel?.backgroundColor? data?.button?.cancel?.backgroundColor: '#ffffff',
'color': data?.button?.cancel?.color? data?.button?.cancel?.color: '#333333'
}">
{{data?.button?.cancel?.title}}
</button>
<button *ngIf="data?.button?.discard?.title" (click)="closeDialog(true)" class="btn-primary mr-2" [ngStyle]="{
'background-color': data?.button?.discard?.backgroundColor? data?.button?.discard?.backgroundColor: '#00c19f',
'color': data?.button?.discard?.color? data?.button?.discard?.color: '#ffffff'
}">
{{data?.button?.discard?.title}}
</button>
<button *ngIf="data?.button?.success?.title" (click)="closeDialog(true)" class="btn-primary" [ngStyle]="{
'background-color': data?.button?.success?.backgroundColor? data?.button?.success?.backgroundColor: '#00c19f',
'color': data?.button?.success?.color? data?.button?.success?.color: '#ffffff'
}">
{{data?.button?.success?.title}}
</button>
</div>
dialog.component.ts
closeDialog(isSuccess) {
this.dynamicDialogRef.close({ isSuccess, data: this.data });
}
Но когда я нажимаю на любую кнопку модального режима, она открывается снова и снова. Так что это не закрытие. Как мне закрыть в .onClose
subsriber?
Когда я попытался включить DynamicDialogRef
в свой компонент, чтобы он выдавал мне эту ошибку
StaticInjectorError(AppModule)[SidebarComponent -> DynamicDialogRef]:
StaticInjectorError(Platform: core)[SidebarComponent -> DynamicDialogRef]:
NullInjectorError: No provider for DynamicDialogRef!
Пожалуйста, объясните мне, что я здесь делаешь неправильно?