I am currently working on creating a shared component for file uploads that can be reused whenever necessary. Interestingly, when I include the file upload code in the same HTML as the form, the validation functions properly. However, if I extract it into a separate component, the validation fails to work.
It is important to note that I only want to implement validation for files in certain components and not in others.
Please refer to this StackBlitz link to see the code example I have been experimenting with:
<form [formGroup]="formLocation" (ngSubmit)="onSubmitFarmLocation()">
<div class="form-row">
<div class="form-group col-sm-4">
<label>Property Identification Number</label>
<input class="form-control" type="text" formControlName="propertyIdentificationNumber"
[class.invalid]="!formLocation.controls['propertyIdentificationNumber'].valid && formLocation.controls['propertyIdentificationNumber'].touched " >
<div
*ngIf="!formLocation.controls['propertyIdentificationNumber'].valid && (formLocation.controls['propertyIdentificationNumber'].touched || isSubmitted)">
<div class="invalid-feedback" style="display: block;">Please enter property identification
Number
</div>
</div>
</div>
<hr>
<app-sharedfile></app-sharedfile>
<div class="form-row">
<div class=" ml-auto pb-3">
<button type="submit" class="btn btn-primary" >Submit</button>
</div>
</div>
</div>
</form>