【发布时间】:2020-03-15 05:28:45
【问题描述】:
我的组件正在调用一个动作并使用@Effect 打开对话框。 对话框将数据发送回@Effect。我可以在@Effects 中使用 .afterClosed() 查看数据,但我不知道如何使用 .afterClosed() 将其发送到组件。
这是组件调用对话框的方式:
this.store.dispatch(new fromWorkspace.ShowDialog());
这是效果中的对话框:
@Effect({ dispatch: false })
showDialog$ = this.actions$.pipe(
ofType(WorkspaceActionTypes.ShowDialog),
map(action => {
this.dialogRef = this.addPersonDialog.open(PersonSelectorComponent, {
disableClose: false,
hasBackdrop: true,
restoreFocus: true,
data: { }
});
// I can see the data here;
this.dialogRef.afterClosed().subscribe(result => console.log(result));
})
);
以下是 Dialog 发送数据的方式:
constructor(@Inject(MAT_DIALOG_DATA) public data: any,
public dialogRef: MatDialogRef<PersonSelectorComponent>) { }
addPerson(event: MatAutocompleteSelectedEvent) {
if (event.option.selected) {
const person = event.option.value;
if (person) {
this.dialogRef.close(person);
// data is correct here;
console.log(person);
}
}
回到组件这里是我尝试使用 .afterClose() 的方式:
public dialogRef: MatDialogRef<PersonSelectorComponent>
//this does not work
this.assigneeDialogRef.afterClosed().subscribe(result => console.log(result));
【问题讨论】:
-
尝试在 stackblitz 创建一个演示,以便更快地解决它。
标签: angular rxjs dialog store dialogresult