ngrx-form,ngrx-store,以编程方式更改值

ngrx-form, ngrx-store, change value programmatically

我有以下reducer.ts

export const FORM_ID = 'doctransForm';

export interface FormValue {
  erstellt: string;
}

export const INITIAL_STATE = createFormGroupState<FormValue>(FORM_ID, {
  erstellt: ''
});

export interface State {
  entities: DoctransEntity[];
  errorMessage: string;
  loading: DataState;
  formState: FormGroupState<FormValue>;
}

export const doctransInitialState: State = {
  entities: [],
  errorMessage: null,
  loading: DataState.LOADED_STATE,
  formState: INITIAL_STATE
}

const _doctransReducer = createReducer(
  doctransInitialState,
  onNgrxForms(),
  on(formValueChange, (state, { type, ...update }) => ({ ...state, ...update })),
  on(DoctransActions.resetForm, (state, action) => ({ ...state, formState: INITIAL_STATE })),
  on(DoctransActions.setErstellt, (state, action) => ({ ...state, formState: { ...state.formState, value: { ...state.formState.value, erstellt: action.erstellt} }})),
);

export function doctransReducer(state: State, action: Action) {
  return _doctransReducer(state, action);
}

html 中的输入字段:

<input [ngrxFormControlState]="doctransFormState.controls.erstellt">

现在我只想以编程方式简单地更改值。

我尝试了以下方法:

this.store.dispatch(setErstellt({erstellt: 'lala test'}));

    const control = createFormControlState<string>('doctransFormState.controls.erstellt', '');
    const updatedControl = setValue('new Value1')(control);
    const updatedControlUncurried = setValue(control, 'newValue2');
    const updatedControlViaAction = formStateReducer(control, new SetValueAction(control.id, 'newValue3'));

但没有任何效果。看来我不明白如何从这里使用 setValue:https://ngrx-forms.readthedocs.io/en/master/user-guide/updating-the-state/#setting-the-value

有人能帮忙吗?

终于。知道了:

this.store.dispatch(new SetValueAction('doctransForm.erstellt', 'newValue3'));