Set Form to Pristine without clearing data

前端 未结 7 1524
暖寄归人
暖寄归人 2021-01-31 07:35

I have a form that displays a list of elements. They all share a common save button which is disabled until the form becomes dirty. Then

7条回答
  •  无人及你
    2021-01-31 07:59

    If you happen to be using Template-Driven forms and you have something like this in your component: @ViewChild('myForm') myform: NgForm;

    I've found that the markAsPristine() is a function on the form property of your form. So it would be this.myform.form.markAsPristine().

    Just thought I'd add this in case others come across markAsPristine() as not being defined.

提交回复
热议问题