Ng-select: "this" keyword is undefined in searchFn

Created on 22 Aug 2019  路  3Comments  路  Source: ng-select/ng-select

Describe the bug
"this" keyword is undefined in searchFn

To Reproduce
Steps to reproduce the behavior (if example is not provided):

  1. Use "this" keyword in searchFn

Expected behavior
"this" should not be undefined in searchFn

Screenshots
Screen Shot 2019-08-22 at 11 40 22 AM
Screen Shot 2019-08-22 at 11 38 39 AM

Desktop (please complete the following information):

  • OS: MAC
  • All Browsers
needs triage

Most helpful comment

For anyone else landing here, here is the correct syntax:

searchFn = (term: string, item: any) => {
  console.log(this);
  return true;
}

All 3 comments

For anyone else landing here, here is the correct syntax:

searchFn = (term: string, item: any) => {
  console.log(this);
  return true;
}

for anyone else landing here, a decent example:

 public searchFn(term: string, pigeon: Pigeon): boolean {
    const ringNumber = pigeon.ringNumber.toLocaleLowerCase();
    const name = pigeon.name.toLocaleLowerCase();
    term = term.toLocaleLowerCase();

    return ringNumber.indexOf(term) !== -1 || name.indexOf(term) !== -1;
  }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

siddharth1903 picture siddharth1903  路  4Comments

wc200107 picture wc200107  路  4Comments

d4rkc0de picture d4rkc0de  路  4Comments

danilocgraciano picture danilocgraciano  路  4Comments

shawnshaddock picture shawnshaddock  路  3Comments