My current text filter successfully filters an array and outputs only the exact case match. I want to be able to search without matching the case unaffecting the search results in their respective cases.
users = [
{fname: 'John', lname: 'doe'},
{fname: 'Jane', lname: 'Doe'}
];
<h3>USERS</h3>
<input type="text" Name="userSearch" [(ngModel)]="userSearch">
<ul *ngFor="let user of users">
<li>{{ user.fname }} {{ user.lname }}</li>
</ul>
Search Text:
doe
Search Result:John doe
Expected Results:John doe
,Jane Doe
Current text filter Pipe:
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({ name: 'textFilter' })
export class TextFilter implements PipeTransform
{
transform(value: any, term: any) {
if (!term) { return value; }
return value.filter((item: any) => {
for (let prop in item) {
if (typeof item[prop] === 'string' && item[prop].indexOf(term) > -1) {
return true;
}
}
return false;
});
}
}