I'm having an array customerList: Array<String> = []; and a function which pushes the value from server into this array. It's working fine except when i use .filter() on this array it gives me undefined error.
This code is:
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())
);
);
}
HTML Code:
<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() in findChoices() is giving the error.
P.S.- I'm using this package
console.log(this.customerList)to the start offindChoices, and add the output to this question please?findChoicesfrom? Can you add that code as well please?console.log(this)from inside that function, does it print the name of your component?