Why building angular forms with formcontrol.values not setting the validations

Viewed 24

I needed to create form in this way. app.ts file ->

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

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

form = { coursename: this.courseNameControl.value, content: this.contentControl.value, } testForm=this.fb.group(this.form)

This form does not create the validations properly. Does anyone have a clue why?

1 Answers

You probably don't NEED to do it this way.

Just do it properly.

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

But to answer your question, your form value is

{ coursename: '', content: '' }

Do you see any validators in that ?

Related