All my reactive forms usually include properties and methods:
@Input() public form: FormGroup; public messages = VALIDATION_MESSAGES; @Output() public onFormSubmit: EventEmitter<any> = new EventEmitter(); @Input() public formData; @Input() public controlsConfig: any; protected abstract fb: FormBuilder; isValidControl(controlName: string): boolean { const control = this.form.controls[controlName]; return control.valid || control.pristine; } onSubmit(): void { const form = this.form; if(form.valid) { this.onFormSubmit.emit(form.value); } }
I selected them in an abstract class
export abstract class BaseReactiveForm {..}
And inherit
@Component({ selector: 'app-login-form', templateUrl: './login-form.component.html', styleUrls: ['./login-form.component.css'] }) export class LoginFormComponent extends BaseReactiveForm implements OnInit { constructor(protected fb: FormBuilder) { super(); } ...}
Is this decision right?
How to do the right thing? What are the forms of practice?
source share