While working on creating a custom pipe in Angular2 for filtering, I encountered the following build error:
Error TS2322: Build: Type '() => string' is not assignable to type 'string'
Below is my sample code:
import { PipeTransform, Pipe } from 'angular2/core';
import { IProduct } from './products';
@Pipe({
name: 'productFilter'
})
export class ProductFilterPipe implements PipeTransform {
transform(value: IProduct[], args: string[]): IProduct[] {
let filter: string = args[0].toLocaleLowerCase ? args[0].toLocaleLowerCase : null;
return filter ? value.filter((product: IProduct) =>
product.productName.toLocaleLowerCase().indexOf(filter) != -1) : value;
}
}
The above-mentioned error occurs at this line of code:
let filter:
Being new to typescript, I am seeking assistance in resolving this issue. Can anyone help me with fixing this problem?