Reputation: 352
I'm currently following an oldish Angular tutorial on Pluralsight and was told to enter the following code
performFilter(filterBy: string): IProduct[] {
filterBy = filterBy.toLocaleLowerCase;
return this.products.filter((product: IProduct) => product.productName.toLocaleLowerCase.indexOf(filterBy) !== -1);
}
Which is supposed to filter a user search. (ie they type the letter 'a', only results containing that letter will display. However, I'm getting a few errors:
1: [ts] Type '() => string' is not assignable to type 'string'. (parameter) filterBy: string
2: [ts] Property 'indexOf' does not exist on type '() => string'. any
I'm new to typescript and not sure if I'm supposed to be casting these variables or something entirely different.
Upvotes: 0
Views: 125
Reputation: 9687
You can try this solution use toLowerCase()
performFilter(filterBy: string): IProduct[] {
filterBy = filterBy.toLowerCase();
return this.products.filter((product: IProduct) => product.productName.toLowerCase().indexOf(filterBy) !== -1);
}
Upvotes: 1
Reputation: 249636
toLocaleLowerCase
is a function, you should call it, the idea is to get the lower case version of the original string:
interface IProduct { productName: string}
function performFilter(filterBy: string): IProduct[] {
filterBy = filterBy.toLocaleLowerCase();
return this.products.filter((product: IProduct) => product.productName.toLocaleLowerCase().indexOf(filterBy) !== -1);
}
Upvotes: 1