
[英]Angular 14 strictly typed reactive forms - How to type FormGroup model using existing interface
[英]Angular 14 strictly typed reactive forms using Generics
export type ModelFormGroup\<T\> = FormGroup\<{
\[K in keyof T\]: FormControl\<T\[K\]\>;
}\>;
我需要 formcontrol 和 formArray 的通用接口。
我能够创建表单控件。 但我不知道如何使用 formarray。
我不确定你想要达到什么目的,但你可以尝试类似的东西:
export class GenericFormArray<T extends AbstractControl> extends FormArray {
constructor(controls: T[]) {
super(controls);
}
}
const fb = new FormBuilder();
const formArray = new GenericFormArray([
fb.array([{age: 25, name: "fu"}, {age: 12, name: "bar"}]),
]);
你看过: Angular 强类型响应式 forms吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.