I'm new to Angular, I'm trying to set a value to an input using typescript to an HTML input, it is working fine however, when I submit the form it reads the value as an empty string, if I typed anything in the input in addition to the value that has been set the from submits with the value successfully, but doesn't submit if the value is set without changing anything manually, please advise if there is a better approach or how to correct this, thanks in advance.
company.component.html
<input type="text" id="LogoImageUrl" formControlName="LogoImageUrl">
company.component.ts
this.editCompanyForm = this.fb.group({
LogoImageUrl: new FormControl({ value: ''})
})
this.image = (
<HTMLInputElement>document.getElementById("LogoImageUrl")
).value = this.imageUrl
uploadFile(file) {
const contentType = file.type;
const bucket = new S3(
{
accessKeyId: 'key',
secretAccessKey: 'key',
region: 'region'
}
);
const params = {
Bucket: 'name',
Key: 'url' + file.name,
Body: file,
ACL: 'public-read',
ContentType: contentType
};
bucket.upload(params, function (err, data) {
if (err) {
console.log('There was an error uploading your file: ', err);
return false;
}
console.log('Successfully uploaded file.', data);
return true;
});
bucket.upload(params).on('httpUploadProgress', function (evt) {
console.log(evt.loaded + ' of ' + evt.total + ' Bytes');
}).send(function (err, data) {
if (err) {
console.log('There was an error uploading your file: ', err);
return false;
}
this.imageUrl = data.Location;
this.editCompanyForm.patchValue({
'LogoImageUrl': this.imageUrl
});
return true;
});
}