I am currently working on an Angular pipe that filters results based on user input. The problem I'm encountering is that some of the results do not have a value, resulting in this error message:
Cannot read property 'toLocaleLowerCase' of null
Below is the code for my pipe:
transform(value: QueuedTemplateDto[], filterBy: string): QueuedTemplateDto[] {
filterBy = filterBy ? filterBy.toLocaleLowerCase() : null;
return filterBy
? value.filter((check: QueuedTemplateDto) => check.user.toLocaleLowerCase().indexOf(filterBy) !== -1)
: value;
}
I attempted to add an if statement to only run the code if the check.user attribute is not null, but encountered errors every time I tried to implement it.
My knowledge of JavaScript is limited in this area. I would greatly appreciate any assistance!