getset formBuilder 控制参数

有两种方法可以设置 formBuilder 控件参数。

  1. 初始化时:
exampleForm : FormGroup;
constructor(fb: FormBuilder){
  this.exampleForm = fb.group({
      name : new FormControl({value: 'default name'}, Validators.compose([Validators.required, Validators.maxLength(15)]))
   });
}

2.初始化后:

this.exampleForm.controls['name'].setValue('default name');

获取 formBuilder 控件值:

let name = this.exampleForm.controls['name'].value();