I'm looking for a filtering solution that will live filter a repeated set of elements. I have a basic pipe solution found in the answers here.
What I've found is that <input [(ngModel)]='query'/> will only work if it's within the same component.
However - I need to have the filter value coming from pre populated radio buttons within another component.
Here is my code so far.
filter.component
<div class="topic" *ngFor="let topic of topics">
{{topic.term}}
<input [(ngModel)]="query" type="radio" name="topicFilter" [value]="topic.term"/>
</div>
grid.component
<router-outlet></router-outlet> // this pulls in the filter.component
<input [(ngModel)]="query"> // this is a text input that works as wanted ( for showing what I'm wanting to achieve )
<grid-item *ngFor="let user of users | topicFilterPipe: 'topic':query">
<a [routerLink]="['user-story', user.uid]">
<h1>{{user.fname}}</h1>
</a>
{{user.topic}}
</grid-item>
filter.pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'topicFilterPipe'
})
export class TopicFilterPipePipe implements PipeTransform {
public transform(value: Array<any>, keys: string, term: string) {
console.log('pipe has run');
if (!term) return value;
return (value || []).filter((item) => keys.split(',').some(key => item.hasOwnProperty(key) && new RegExp(term, 'gi').test(item[key])));
}
}
Basically - trying to implement the same method that the text input does, but with the selected radio that is within the filter.component. However I'm struggling to pass the selected value into the pipe & then filter using ngModel. Thank you!
NOTE: I'm VERY new to angular2 + The filter component must remain in a seperate component