【发布时间】:2021-12-04 20:29:45
【问题描述】:
我是 Angular 的新手。我遇到了具有三个变体的代码。我想知道这三个在响应式表单(表单组、表单构建器和表单控件)中的实现有何不同。
是否有任何优先级基于一种方法的应用程序性能而不是另一种方法,还是只是偏好?
addressFormControl = new FormControl(undefined, [
Validators.required,
Validators.address,
]);
export class BusinessComponent {
BusinessForm = new FormGroup({
email: this.emailFormControl,
firstName: new FormControl(''),
lastName: new FormControl(''),
address: new FormGroup({
street: new FormControl(''),
city: new FormControl(''),
state: new FormControl(''),
zip: new FormControl('')
})
});
}
export class BusinessComponent {
constructor(private fb: FormBuilder) { }
businessForm = this.fb.group({
business: this.businessFormControl,
firstName: [''],
lastName: [''],
address: this.fb.group({
street: [''],
city: [''],
state: [''],
zip: ['']
}),
});
}
【问题讨论】:
标签: angular typescript angular-reactive-forms form-control formgroups