I am looking to use Angular Material Autocomplete to display only Employee name from the Rest API that is returning array of data as below:
{
"employees": [
{
"employeeID":"5657",
"employeeName":"James Carter",
"employeeDept": ["Dept1", "Dept2", "Dept3"]
},
{
"employeeID":"5868",
"employeeName":"Helen Burt",
"employeeDept": ["Dept5", "Dept2", "Dept6"]
}
]
}
Defined the model as below:
interface Employee {
employeeID: number
empoyeeName: string
employeeDept: string[]
}
I am using below subscribe method to get the data
this.getAPI.getEmployees()
.pipe(pluck('employees'))
.subscribe(e => {
this.employees = e;
});
Below is the code for Filtering:
this.filteredOptions = this.myControl.valueChanges.pipe(
startWith(''),
map(value => this._filter(value))
);
private _filter(value: string): EmployeesList[] {
const filterValue = value.toLowerCase();
return this.employees.filter(option => option.employeeName.toLowerCase().indexOf(filterValue) === 0);
}
But nothing seems to be working in the input search(autocomplete). Please advise.