You must use Pipes and Observations.
Here is a simple example of your problem:
Each time the user selects a value, a change event occurs. Using an event, you can easily get the value and pass it to the observed thread.
You can access the observable from your SelectDataComponent to your table component (AppComponent) using the ref element (#)
Monitor your myCustomFilter and subscribe to the monitored via the asynchronous channel provided by angular.
*ngFor="let data of someData | myCustomFilter: (selectDataComp.selectedValues$ | async)
Appcompponent
import {Component} from '@angular/core'; @Component({ selector: 'app-root', template: ` <app-select-data #selectDataComp></app-select-data> <table> <th>Value</th> <th>id</th> <tr *ngFor="let data of someData | myCustomFilter: (selectDataComp.selectedValues$ | async)"> <td>{{data?.value}}</td> <td>{{data?.id}}</td> </tr> </table> `, styles: [] }) export class AppComponent { someData = [ { value: 'ABC', id: '123'}, { value: 'ABC', id: '12'}, { value: 'DEF', id: '23'}, { value: 'DEF', id: '1233'}, { value: 'ABC', id: '13'}, { value: 'DEF', id: '1'}, { value: 'DEF', id: '34'}, { value: 'ABC', id: '56'}, { value: 'ABC', id: '13'}, { value: 'DEF', id: '123'}, { value: 'HIJ', id: '113'} ]; }
SelectDataComponent
import { Component } from '@angular/core'; import {Subject} from 'rxjs/Subject'; @Component({ selector: 'app-select-data', template: ` <div> <select (change)="onChange($event.target.value)"> <option value="">--please select--</option> <option *ngFor="let option of options" [value]="option"> {{ option }} </option> </select> </div> `, styles: [] }) export class SelectDataComponent { public selectedValues$: Subject<string> = new Subject(); public options = ['ABC', 'DEF']; onChange(selectedValue) { this.selectedValues$.next(selectedValue); } }
myCustomFilter
import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'myCustomFilter' }) export class MyCustomFilterPipe implements PipeTransform { transform(data: any, toFilter: string): any { if (!toFilter) { return data; } return data.filter(d => d.value === toFilter); } }
Appmodule
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import {BrowserAnimationsModule} from '@angular/platform- browser/animations'; import { SelectDataComponent } from './select-data.component'; import { MyCustomFilterPipe } from './my-custom-filter.pipe'; @NgModule({ declarations: [ AppComponent, SelectDataComponent, MyCustomFilterPipe, ], imports: [ BrowserModule, BrowserAnimationsModule, ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }