I'm developing an Angular 6 project which has tons of forms. One FormGroup can contain more than 10 fields and could be reused across one app multiple times.
So, I'm asking how can I better organize my app? Currently one form.component.ts
has more than 200 lines of code where about 70% the form create is going.
Is there a way to split this into reusable parts? I've tried to create a class with static
method which returns a FormGroup
made by FormBuilder
but this doesn't seem to be working.
It was about
export class myClass {
constructor(private fb: FormBuilder) {}
static createFormGroup(): FormGroup {
this.fb.group({
// some stuff goes here
});
}
}
I don't know how to deal with this since the instance isn't going to be created since it's static.