Angular / NgRx-在效果中传递通用类型

时间:2019-03-08 01:43:16

标签: angular typescript ngrx ngrx-effects

我想创建一个采用通用类型的动作和效果,但是我不知道如何将通用类型传递给效果

在没有通用类型有效的情况下运行的极简代码:

组件:

this.store.dispatch(
  new fromDialogActions.OpenDialogAction<DetailComponent>({
    component: DetailComponent, config: DIALOG_CONFIG
  })
);

操作:

export class OpenDialogAction<T> implements Action {
  readonly type = DialogActionTypes.OPEN_DIALOG;
  constructor(public payload: OpenDialogPayload<T>) {}
}

效果:

export class DialogEffects {
  @Effect({ dispatch: false })
  openDialog$: Observable<null> = this.actions$.pipe(
    ofType(fromDialogActions.DialogActionTypes.OPEN_DIALOG),
    map((action: fromDialogActions.OpenDialogAction<DetailComponent>) => action.payload)
  );
}

如何在此处传递通用名称:map ((action: fromDialogActions.OpenDialogAction <DetailComponent>) => action.payload)而不是DetailComponent? Ty

0 个答案:

没有答案