小编Ven*_*ram的帖子

反应式表单中的角度表单组与表单控件和表单生成器

我是角度新手。我发现该代码具有三种变体。我想知道这三者在响应式表单(表单组、表单生成器和表单控件)中实现有什么区别。

是否存在基于一种方法的应用程序性能相对于另一种方法的优先级,或者这只是偏好?

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: ['']
    }),
  });
}
Run Code Online (Sandbox Code Playgroud)

typescript form-control angular angular-reactive-forms formgroups

3
推荐指数
1
解决办法
3651
查看次数