fknop / angular-pipes

Useful pipes for Angular
https://fknop.gitbook.io/angular-pipes/
MIT License
732 stars 157 forks source link

this undefined within where pipe #96

Open Et3rnal opened 5 years ago

Et3rnal commented 5 years ago
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request

Current behavior

Using the where pipe to call the function I can't access this

num = 1
aEqualsOne(item) {
  return item.a === this.num;
}

If this is not a bug, how can I pass parameters to the pipe?

Et3rnal commented 5 years ago

I tried not to use it without the function I noticed in order for it to return any result. It has to find an exact match <= how can I change this? for example, 3 characters of the word is enough to return a match also it is case sensitive

rosostolato commented 3 years ago

@Et3rnal you might have already found the answer, but the solution is to use arrow function instead:

num = 1
// declare as a normal public variable
aEqualsOne = (item) => {
  return item.a === this.num;
}