为什么要用formcontrol构建有角度的表单?没有设置验证的值



我需要用这种方式创建表单。App.ts文件->

coursenameconcontrol = new FormControl(";[Validators.required Validators.minLength (2)]);

contentControl = new FormControl(", Validators.required);

form = {coursename: this.courseNameControl。价值,内容:this.contentControl。{testForm=this.fb.group(this.form)

这个表单没有正确创建验证。有人知道为什么吗?

您可能不需要这样做。

把它做好。

testForm = this.fb.group({
coursename: ['', [Validators.required, Validators.minLength(2)]],
content: ['', [Validators.required]]
});

但是回答你的问题,你的form值是

{ coursename: '', content: '' }

你看到验证器了吗?

最新更新