Issue
when i edit the data click the selected row on the table select row record successfully pass in to form name and description on textbox but dropdown list but displayed Selected Value need to be pass into the dropdown list Angular Material but it is not passing the value what i tried so far I attached below.
this is design task.component.html
<mat-form-field class="example-full-width">
<mat-label>Complete</mat-label>
<mat-select [(ngModel)]="complete" name="complete">
<mat-option value="true">True</mat-option>
<mat-option value="false">False</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field class="example-full-width">
<mat-label>Employee</mat-label>
<mat-select matNativeControl [(ngModel)]="employeeId" name="employeeId">
<mat-option *ngFor="let EmployeeItem of EmployeeArray" value="{{ EmployeeItem.employeeid}}">
{{ EmployeeItem.employeename }}
</mat-option>
</mat-select>
</mat-form-field>
task.component.ts
setUpdate(data:any)
{
this.complete = data.complete;
this.employeeId = data.employeeId;
}
getAllEmployees()
{
this.http.get("http://localhost:8075/api/v1/employee/getAllEmployees")
.subscribe(
(resultData: any) => {
console.log(resultData);
this.EmployeeArray = resultData;
},
(error) => {
console.error("Error fetching employee data:", error);
}
);
}
Solution
<mat-select (valueChange)="setUpdate($event)" matNativeControl [(ngModel)]="employeeId" name="employeeId">
<mat-option *ngFor="let EmployeeItem of EmployeeArray" value="{{ EmployeeItem.employeeid}}">
{{ EmployeeItem.employeename }}
</mat-option>
</mat-select>
setUpdate(data:any){
this.complete = data.complete;
this.employeeId = data.employeeId;
}
Answered By - codewithharshad
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.