johnnyfittizio johnnyfittizio - 6 months ago 23
AngularJS Question

AngularJs: How to avoid lettercase while filtering

THE SITUATION:

I had to make my own filter, instead of using the normal angular filter, because of a particular situation:

I have a nested object on four levels: Programs - Days - Halls - Presentations.
Each hall is an accordion containing the relative presentations.

Anyway the filter i made is working properly.

Except one thing: right now the filter is letter case.

So if a presentation name is 'Automation' and the user type 'automation' it won't show up in the results.

THE CODE:

Right now is looking for a simple indexOf of the string entered by the user inside the presentation name:

angular.forEach(value_halls.presentations, function(presentation_info, key_presentation)
{
var name = presentation.name;
var index = name.indexOf($rootScope.filter.name);

if (index > -1 )
{
$rootScope.program_list_filtered.push(presentation_info);
}

});


THE QUESTION:

Do you know how can i avoid letter case while filtering?

Thank you!

Answer

You can use toLowerCase on both strings:

var index = name.toLowerCase().indexOf($rootScope.filter.name.toLowerCase());