Html 如何在“角度”对话框中传递数据
现在,在我的编辑页面中,用户可以删除节和子节,但我正在考虑添加确认对话框,以便用户不会意外地删除其中任何一个 我不确定如何在确认对话框组件和编辑页面组件之间传递数据 该项目不会在Stackblitz上运行,但我已经将这两个组件上传到这里component/EditComponent.ts 所以,如果有人能帮我查一查,我将不胜感激。谢谢 编辑组件.TSHtml 如何在“角度”对话框中传递数据,html,angular,typescript,angular-material,dialog,Html,Angular,Typescript,Angular Material,Dialog,现在,在我的编辑页面中,用户可以删除节和子节,但我正在考虑添加确认对话框,以便用户不会意外地删除其中任何一个 我不确定如何在确认对话框组件和编辑页面组件之间传递数据 该项目不会在Stackblitz上运行,但我已经将这两个组件上传到这里component/EditComponent.ts 所以,如果有人能帮我查一查,我将不胜感激。谢谢 编辑组件.TS this is how I open Comfirmation Dialog openSection() { let dialogR
this is how I open Comfirmation Dialog
openSection() {
let dialogRef = this.dialog.open(ConfirmDialogComponent, {
data: {
isSection: true, isSubsection: false
},
}
);
}
openSubsection(){
this.dialog.open(ConfirmDialogComponent, {
data: {
isSubsection: true, isSection: false
},
});
}
//This is how I'm deleting right now without confirmation Dialog
delete(sec) {
if (this.isSection) {
this.HelpService.deleteHelpSection(sec.id).subscribe(() => {
const index = this.mappedSections.findIndex((value) => value.id == sec.id);
this.mappedSections = this.mappedSections.filter(section => section.id != sec.id)
if (~index) {
this.HelpService.deleteHelpSubsection(sec.id).subscribe(() => {
this.mappedSections = this.mappedSections.filter(section => section.id != sec.id);
})
}
})
} if (this.isSubsection) {
this.HelpService.deleteHelpSubsection(sec.id).subscribe(() => {
const index = this.mappedSections.findIndex((value) => value.id == sec.parentId);
if (~index) {
this.mappedSections[index].subSections = this.mappedSections[index].subSections.filter((subsection) => subsection.id != sec.id)
}
})
}
}
订阅来自模式的结果
openSection() {
let dialogRef = this.dialog.open(ConfirmDialogComponent, {
data: {
isSection: true, isSubsection: false
},
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed', result);
if(result){
this.delete(sec)
}
});
}
从模态组件传递数据
<button mat-raised-button (click)="closeDialog()">Close</button>
关闭
构造函数(
公共dialogRef:MatDialogRef
) {}
closeDialog(){
此.dialogRef.close(true);
}
检查此工作样本您好,谢谢您的帮助,但我不确定this.fromPage和this.fromDialog来自何处,因为我在这两个方面遇到了一个错误:(fromPage和fromDialog是ConfirmDialogComponent的变量。
constructor(
public dialogRef: MatDialogRef<ConfirmDialogComponent>
) {}
closeDialog() {
this.dialogRef.close(true);
}