'new FormControl',对于反应形式是强制性的 - Angular
'new FormControl', is mandatory for reactive forms - Angular
我在 Angular 项目中使用响应式表单实现了我的表单。在这里,我使用 formGroup 和 'new FormControl' 来创建字段。现在我怀疑是否有任何方法可以在不使用 Formcontrol 的情况下实现字段。
是的,只需使用 FormBuilder。像这样:
import { FormBuilder } from '@angular/forms';
constructor(private fb: FormBuilder) { }
this.productForm = this.fb.group({
productName: ['', [Validators.required,
Validators.minLength(3),
Validators.maxLength(50)]],
productCode: ['', Validators.required],
starRating: ['', NumberValidators.range(1, 5)],
tags: this.fb.array([]),
description: ''
});
请注意,不需要 new FormControl()
。
在此处查看文档以获取更多信息:https://angular.io/guide/reactive-forms#generating-form-controls-with-formbuilder
我在 Angular 项目中使用响应式表单实现了我的表单。在这里,我使用 formGroup 和 'new FormControl' 来创建字段。现在我怀疑是否有任何方法可以在不使用 Formcontrol 的情况下实现字段。
是的,只需使用 FormBuilder。像这样:
import { FormBuilder } from '@angular/forms';
constructor(private fb: FormBuilder) { }
this.productForm = this.fb.group({
productName: ['', [Validators.required,
Validators.minLength(3),
Validators.maxLength(50)]],
productCode: ['', Validators.required],
starRating: ['', NumberValidators.range(1, 5)],
tags: this.fb.array([]),
description: ''
});
请注意,不需要 new FormControl()
。
在此处查看文档以获取更多信息:https://angular.io/guide/reactive-forms#generating-form-controls-with-formbuilder