For me even with [formGroup]
the error was popping up "Cannot find control with name:''"
.
It got fixed when I added ngModel
Value to the input box along with formControlName="fileName"
<form class="upload-form" [formGroup]="UploadForm">
<div class="row">
<div class="form-group col-sm-6">
<label for="fileName">File Name</label>
<!-- *** *** *** Adding [(ngModel)]="FileName" fixed the issue-->
<input type="text" class="form-control" id="fileName" [(ngModel)]="FileName"
placeholder="Enter file name" formControlName="fileName">
</div>
<div class="form-group col-sm-6">
<label for="selectedType">File Type</label>
<select class="form-control" formControlName="selectedType" id="selectedType"
(change)="TypeChanged(selectedType)" name="selectedType" disabled="true">
<option>Type 1</option>
<option>Type 2</option>
</select>
</div>
</div>
<div class="form-group">
<label for="fileUploader">Select {{selectedType}} file</label>
<input type="file" class="form-control-file" id="fileUploader" (change)="onFileSelected($event)">
</div>
<div class="w-80 text-right mt-3">
<button class="btn btn-primary mb-2 search-button cancel-button" (click)="cancelUpload()">Cancel</button>
<button class="btn btn-primary mb-2 search-button" (click)="uploadFrmwrFile()">Upload</button>
</div>
</form>
And in the controller
ngOnInit() {
this.UploadForm= new FormGroup({
fileName: new FormControl({value: this.FileName}),
selectedType: new FormControl({value: this.selectedType, disabled: true}, Validators.required),
frmwareFile: new FormControl({value: ['']})
});
}