Check if FormGroup has been submitted

时间:2017-06-15 09:27:51

标签: angular

In template-driven form, we can check that with the submitted property from NgForm. But how to achieve that in Model-driven form?

2 个答案:

答案 0 :(得分:14)

我发现您可以将ngFormformGroup一起使用:

<form [formGroup]='form' #ngForm="ngForm" (ngSubmit)='validation(ngForm)' 
  [ngClass]="{ 'form-unsubmitted': !ngForm.submitted}">

答案 1 :(得分:2)

create one variable IsSubmitted = false into component. once submit a button you can set it true into onSubmit() function. for example :

onSubmit(): void{
     this.isSubmited = true;
  // code....
}

set it again false into after response