I am trying to wrap my head around this problem for some time now.
When I try to have an input in a form only if a condition is true, I receive an error, that invalid could not be read from undefined.
When using the elvis operator I don't get the error anymore, but even if the input is displayed, invalid & dirty, I still don't see the error message.
<form #myForm="ngForm">
... other inputs ...
<input *ngIf="model.type === 'V'"
name="price"
type="number"
required
[(ngModel)]="model.price"
#price="ngModel">
<div class="errors" *ngIf="price?.invalid && price?.dirty">
Problem detected
</div>
</form>
Anyone a hint what I am missing?