form control inside ngIf is still invalidating the whole form

371 views Asked by At

I have a input component that uses a Control for validation.
This component is being used within a label that has a ngIf attached.
When the ngIf is false, the input is not being rendered, thats expected and ok, but the problem is that it stills invalidates the whole form.

What could I do to so that the form is not invalidated by an input that is inside a false ngIf statement.

thanks

1

There are 1 answers

0
Jonathan On BEST ANSWER

Found the answer.
I didn't know that the ngIf destroys the components inside it when it gets a false expression result. My component dynamically creates a validity Control and attach it to the ControlGroup of a Submitter component on ngInit.
Now I need to detach it from the controlgroup on ngDestroy.