I want to show up validation for the fields which are empty and for that i used the following method but its not working.Can anyone suggest me help.Thanks.
My template,<
Please check below solution.
DEMO : https://plnkr.co/edit/mJFftirG3ATDpnJRWmKN?p=preview
export class AppComponent {
form: FormGroup;
constructor(private formBuilder: FormBuilder){
this.submitted=false;
this.form = formBuilder.group({
lastname: ['', Validators.required],
});
}
onSubmit(form)
{
this.submitted=true;
console.log(form);
if(form.valid) //<<<### submit form is it is valid only
{
console.log('form submitted');
}
}
}