如何使用数组作为@ ngrx / store的createAction中的参数

问题描述 投票:0回答:1

我想创建一个以数组作为参数的Action,但这不输入check:

export const action_organizations_available = createAction(
  CoreActionTypes.ORGANIZATIONS_AVAILABLE,
  props<Organization[]>()
);

我得到props(): "arrays are not allowed in action creators"。当类型不是数组时,它可以正常工作。

使用props<{ organizations: Organization[] }>有效,但我想知道这是否是最佳实践。

期望数组作为操作中的参数时的最佳实践是什么?

angular ngrx ngrx-store
1个回答
1
投票

您必须将其包装到一个对象中:

export const action_organizations_available = createAction(
  CoreActionTypes.ORGANIZATIONS_AVAILABLE,
  props<{ organizations: Organization[] }>()
);
© www.soinside.com 2019 - 2024. All rights reserved.