NGRX形式,NGRX商店,以编程方式更改值
我有以下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/master/user-guide/updating-the-state/#setting-the-the-value
有人可以帮忙吗?
I have the following 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);
}
An input-field in html:
<input [ngrxFormControlState]="doctransFormState.controls.erstellt">
Now i just want to simply change the value programmatically.
I tried the following:
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'));
But nothing works. It seems i dont understand how to use the setValue from here: https://ngrx-forms.readthedocs.io/en/master/user-guide/updating-the-state/#setting-the-value
Can anyone help out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后。知道了:
Finally. Got it: