Hi
I have below ts file and i want when user clicks on Edit all data should be shown in modal
onEdit(Id:number)
{
this.empSrv.getEmpById(Id).subscribe((res:any)=>{
this.objEmployee = res.data;
console.log(res.data);
this.form.patchValue({
'empName':res.data.empName?res.data.empName:''
})
this.openModal();
})
}
*********************
Thanks
Naimish MakwanaPosted May 27, 2024, 5:23 AM
It seems like you want to populate the form with the employee data when the Edit button is clicked. You’re on the right track, but you need to patch all the form controls with the corresponding properties from
res.data. Here’s how you can modify youronEditfunction:This will ensure that all the form fields are populated with the corresponding employee data when the Edit button is clicked. If a particular property does not exist in
res.data, it will default to an empty string.Also, please note that the
@ifand@elsesyntax you’re using is not valid in Angular templates. You should use*ngIfinstead. Here’s how you can modify your buttons:This will show the Save button if
objEmployee.empIdis 0, and the Update button otherwise. The Update button will callonEditwith the currentobjEmployee.empIdwhen clicked.Thanks