I have a form that is pulled up multiple times. I need to be able to reset the submitted flag on the form to false each time it comes up to remove any possible error messages that might have been left over from the last time.
The only way I've found to set the submitted flag back to false is to use the ngForm.resetForm(model) method.
This works well enough, except that it doesn't ngModel bind to any objects that are nested within the top level model.
Given the following object:
model: {
firstName: 'John',
contact: {
lastName: 'Smith'
}
}
and the following inputs:
<input type='text' name='firstName' [(ngModel)]='model.firstName' />
<input type='text' name='lastName' [(ngModel)]='model.contact.lastName' />
The first time the form loads, everything appears correctly.
However, if you submit the form and then call this.myForm.resetForm(this.model), it won't bind model.contact.lastName. It does bind model.firstName just fine.
I have included a plunkr that illustrates the problem here.
Is there any way to reset the submitted flag outside of resetForm? Or can someone explain why the model.contact.lastName field is not binding correctly when resetForm is called?