I have a basic autocomplete. A list of objects where I pull out the list of a a string property and want to filter and select on it. Any idea why everything works and I see the list of names. But when I type in the box the filter does not happen ?
<mat-form-field>
<input type="text" placeholder="Filter by Last Name" [formControl]="fcOnBehalfLastName" matInput
[matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let eln of allEmployeesLastNames" [value]="eln">
{{eln}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
fcOnBehalfLastName = new FormControl();
filteredLastNames: Observable<any>;
allEmployeesLastNames: string[];
constructor(private fb: FormBuilder) {
console.log('-----OrderStep1xComponent');
}
private _filter(value: string): string[] {
const filterValue = value.toLowerCase();
return this.allEmployeesLastNames.filter(eln => eln.toLowerCase().includes(filterValue));
}
ngOnChanges(changes: SimpleChanges) {
if (changes.allEmployees && changes.allEmployees.currentValue) {
this.allEmployeesLastNames = this.allEmployees.map(o => o.lastName);
}
}
ngOnInit(): void {
this.employeeFilter = new Employee();
this.filteredLastNames = this.fcOnBehalfLastName.valueChanges
.pipe(
startWith(''),
map(value => this._filter(value))
);