在组件中使用 dispatch 触发 Action 时传递参数,参数最终会被放置在 Action 对象中

  1. this.store.dispatch(increment({ count: 5 }))

在创建 Action Creator 函数时,获取参数并指定参数类型

  1. import { createAction, props } from "@ngrx/store"
  2. export const increment = createAction("increment", props<{ count: number }>())
  1. export declare function props<P extends object>(): Props<P>

在 Reducer 中通过 Action 对象获取参数

  1. export const reducer = createReducer(
  2. initialState,
  3. on(increment, (state, action) => ({ count: state.count + action.count }))
  4. )