We are attempting to implement an angular pipe for filtering a list of sub-items, with the goal of removing parent items if there are no child items present. Here is the HTML code snippet we are using:
<div class="row border-bottom item" *ngFor="let item of pageContent | filter: searchText; let i = index">
<div class="col-6">{{item.name}}</div>
<div class="col-6">
<ul>
<li *ngFor="let link of item.content">
{{link.content}}
</li>
</ul>
</div>
</div>
This is how our pipe is defined:
export class FilterPipe implements PipeTransform {
transform(items: AllContent[], searchText: string): AllContent[] {
if (!items) return [];
if (!searchText) return items;
return items.filter(item => {
item.content.filter(c => c.content.toLowerCase().includes(searchText.toLowerCase()))
})
We have been unable to successfully filter out the child items. We have also attempted the following approach:
return items.foreach(item => {
item.content.filter(c => c.content.toLowerCase().includes(searchText.toLowerCase()))
})
Is there something that we might be overlooking or missing in our implementation?