I am working on a function for an Angular Pipe and one of the arguments needs to be a string from the template *ngFor="let row of tableRows | filter: searchText : keyName" and then use that to itterate the object in the pipe's function
in component: let keyName = 'name.value'
pipe:
transform(items: any[], searchText: string, keyName: string = ''): any[] {
if (!items) {
return [];
}
if (!searchText) {
return items;
}
searchText = searchText.toLowerCase();
console.log(keyName);
return items.filter( it => {
return it.keyName.toLowerCase().includes(searchText); //THIS HERE NEEDS TO MATCH THE STRING PROVIDED
});
}
so lets say the argument string name.value is passed into the function, it.keyName.toLowerCase() needs to get interpreted as it.name.value.toLowerCase()
return it[keyName.toLowerCase()].includes(searchText);?