根据您的评论,无法理解完整的代码以及您错过的内容。
请参考我的 plunker 并了解EventEmitter
角度组件通信。
https://plnkr.co/edit/zesHjCIhSjt1TxhpVdeT?p=preview
打开对话框
@Component({
selector: 'dialog-result-example',
templateUrl: 'dialog-result-example.html',
})
export class DialogResultExample {
selectedOption: string;
constructor(public dialog: MdDialog) {}
openDialog() {
const dialog = this.dialog.open(DialogResultExampleDialog);
const sub = dialog.componentInstance.formSubmit$.subscribe(() => {
alert('hi');
});
dialog.afterClosed().subscribe(() => {
sub.unsubscribe();
});
}
}
关闭对话框
@Component({
selector: 'dialog-result-example-dialog',
templateUrl: 'dialog-result-example-dialog.html',
})
export class DialogResultExampleDialog {
@Output() formSubmit$: EventEmitter<boolean>;
constructor(public dialogRef: MdDialogRef<DialogResultExampleDialog>) {
this.formSubmit$ = new EventEmitter();
}
closePop(){
debugger;
this.formSubmit$.emit(true);
this.dialogRef.close();
}
}