Currently, I have an array named
customerList: Array<String> = [];
that is populated with values from a server-side function. Everything seems to be working well until I attempt to use the .filter()
method on this array and encounter an error stating "undefined".
The snippet of code causing the issue is as follows:
customerList: Array<String> = [];
ngOnInit() {
this.customerService.getCustomers().subscribe(res => {
this.customers = res;
for (const cust of res) {
this.customerList.push(cust.first_name);
}
}
);
}
findChoices(searchText: string) {
return this.customerList.filter(item =>
item.toLowerCase().includes(searchText.toLowerCase())
);
);
}
Here's the corresponding HTML snippet:
<mwl-text-input-autocomplete-container>
<input type="text" class="form-control" id="customer_name" name="customer_name" aria-describedby="emailHelp"
placeholder="Customer name" formControlName="customer_name" mwlTextInputAutocomplete
[findChoices]="findChoices"
[getChoiceLabel]="getChoiceLabel" autofocus>
</mwl-text-input-autocomplete-container>
The customerList.filter()
within the findChoices()
method is where the error arises.
P.S.- The angular-text-input-autocomplete package is being utilized in this scenario.