I have a FirebaseListObservable and a BehaviorSubject listening a input filter.
Now I want to merge both guys and return an array filtered with the value from the input to feed the md-table.
I got the exemple from https://material.angular.io/components/table/examples filtering table.
Can anyone help me? Thank you.
Edit:
Now it's working but I'm getting an error when loads the component. After I write something on input field, starts to works fine.
ERROR TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
What am I doing wrong?
export class DataSourcePessoas extends DataSource<any> {
pessoas: FirebaseListObservable<any[]>;
_filterChange = new BehaviorSubject('');
get filter(): string { return this._filterChange.value; }
set filter(filter: string) { this._filterChange.next(filter); }
dados: any[] = [];
constructor(private pessoasService: FirebasePessoasService) {
super();
}
connect(): Observable<any> {
const displayDataChanges = [
this.pessoas,
this._filterChange,
];
this.pessoas = this.pessoasService.BuscarPessoas();
this.pessoas.subscribe(items => {console.log(items); this.dados = items});
return Observable.merge(...displayDataChanges).map(() => {
return this.dados.filter(valor => {
return valor.nome.toLowerCase().indexOf(this.filter.toLowerCase()) !== -1})});
}
disconnect() {}
}