Initially, the Material error works fine. But after adding an item to the list, I need the submitted status to reset. For example, add an item, then click the Add Item button without inputting any text. The error no longer works.
Asked
Active
Viewed 174 times
0
-
Welcome to stackoverflow! Can you provide more information about your problem? Because I'm trying to reproduce it without success! Thank you! – Ricardo Rocha Feb 15 '21 at 17:07
-
Do not work with the html form node directly. Writing `getElementByXy()` is not what you do with angular. Create a form group and call reset on this form group (or on your FormControl if that's the only control.) – Christoph Lütjen Feb 15 '21 at 17:07
-
@RicardoRocha - Steps: Submit form > = alert + input marked as invalid > type "abc" and submit form > = item added > submit form again with empty input > ERR: input not marked as invalid. – Christoph Lütjen Feb 15 '21 at 17:11
2 Answers
0
This accepted answer is what I was looking for. You need to reset the FormGroupDirective
.
New StackBlitz with working example (some other code changes as well).

dawphin777
- 43
- 1
- 7
0
Since there is only one FormControl, we do not need a FormGroup. The FormControl is bound to the input. The FormControl can be used to perform all actions onto the input. There are lot of other unwanted code which have been removed in the StackBlitz below:

T. Sunil Rao
- 1,167
- 5
- 14