I want to add validation on dynamically generated field. This is my code.
projectForm: FormGroup;
constructor(private sanitizer:DomSanitizer,private router: Router,private fb: FormBuilder,private projectService: ProjectService,private fnService:FunctionsService, private userService : UserService) {
this.projectForm = fb.group({
'shirnkrap':[null, Validators.required],
'cd_text':[null, Validators.required],
'assignto':[null, Validators.required],
'projecttype':[null, Validators.required]
});
}
on one function i want to add new validation which will trigger on <select>
change event.
I try this,
this.projectForm.controls['project_name'].setValidators([Validators.required]);
but it give me this error,
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'setValidators' of undefined
So can someone help me how can i add validation?