I need to verify if an object has a value without generating an error. If it does, I want to set it as the value of an input field.
export class DialogServiceTabletAddRowComponent implements OnInit {
service?: string;
constructor(private _dialogRef: MatDialogRef<DialogServiceTabletAddRowComponent>, private _fb: FormBuilder, @Inject(MAT_DIALOG_DATA) public data: ServiceDataToDialog) {
try {
this.service = this.data[this.data.id].allServices[this.data.id][this.data.id].service;
}
catch (e) {
this.service = '';
}
console.log(this.service);
})
}
mainForm = this._fb.group({
service: [this.service, Validators.required]
})
}
console.log(this.service);
returns the correct value but my input field remains empty. Why is that happening?