javascript - Angular FormGroup 无法分配给对象“[object Object]”的只读属性“status”
问题描述
我将ngrx与Angular 12一起使用。下面是redux实现
export interface AdminProductState {
productDetailformValidStatus: FormGroup;
productDetails: ProductDetailsCommand;
}
export const initialState: AdminProductState = {
productDetailformValidStatus: new FormGroup({}),
productDetails: {} as ProductDetailsCommand
};
const reducer = createReducer(
initialState,
on(Product_Form_Validation, (state, action) => (
{
...state,
productDetailformValidStatus: action.productDetailformValidStatus,
productDetails: action.productDetails
}
)),
);
export function AdminProductReducer(state: AdminProductState | undefined, action: Action): any {
return reducer(state, action);
}
productDetailformValidStatus: FormGroup;
定义为FormGroup
并且已初始化为new FormGroup({})
,
从调度的方法我传递新的 FormGroup 如下
ngOnInit(): void {
this.form = this.createControls();
this.adminProductState.productDetailformValidStatus = this.form;
this.productDetailsCommand.categoryId = 'asdasd2323';
this.productDetailsCommand.title = 'hello titile';
this.productDetailsCommand.description = 'thisisthedescription';
this.productDetailsCommand.subCategoryId = 'thisisthetesting';
this.adminProductState.productDetails = this.productDetailsCommand;
this.store.dispatch(Product_Form_Validation(this.adminProductState));
}
protected createControls() {
const group = this.fb.group({});
this.controlsConfig.container.layoutConfig.forEach((layout, index) => {
layout.componentConfig.forEach(controls => {
this.bindControl(controls, group, index)
})
});
return group;
}
现在this.form
包含新控件和表单状态无效,在执行此操作时我面临以下问题
ERROR TypeError: Cannot assign to read only property 'status' of object '[object Object]'
core.js:6456 ERROR TypeError: Cannot add property 0, object is not extensible
ERROR TypeError: Cannot assign to read only property '_rawValidators' of object '[object Object]'
这些错误都来自 core.js。我做错了什么我无法找到它。
来自 redux 工具
解决方案
我必须这样做才能解决问题
ngOnInit(): void {
this.createControlAsyncTask()
.then(() => this.store.dispatch(Product_Form_Validation(this.adminProductState)));
}
createControlAsyncTask() {
return new Promise((resolve, reject) => {
this.form = this.createControls();
this.adminProductState.productDetailformValidStatus = this.form;
resolve('done');
});
}
推荐阅读
- php - PHP 目录问题,无法使用 (../) 返回目录
- sql - 与直接函数调用相比,为什么 CROSS APPLY with Functions 这么慢?
- javascript - 如何检查对象是否已经在 three.js 场景中然后替换它?
- assembly - 汇编(AT&T 格式)操作数值
- c++ - std::vector 移动而不是交换到空向量并释放存储空间
- java - 二维数组打印第一个负数和每行最后一个之间的元素总和
- android - 如何使用 google 签名按钮确定我是否已登录或注册我的 android 应用程序
- sas - SAS 等价于 rleid 函数
- c# - Linq SelectMany 基于两个属性
- javascript - Elm,模型如何与订阅保持同步?