我的所有反应形式通常包括属性和方法:
@Input()
public form: FormGroup;
public messages = VALIDATION_MESSAGES;
@Output()
public onFormSubmit: EventEmitter = 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);
}
}
我在抽象课中选择了它们
export abstract class BaseReactiveForm {..}
并继承
@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();
}
...}
决定是真的吗?
怎么做正确的事情?什么是实践形式?