typescript - Angular 4 show list data from firebase to md-table -
i trying create table load data firebase , show in created table.
here component html
<div fxlayout="row"> <div>dealers</div> <div> <md-form-field floatplaceholder="never"> <input mdinput #filter placeholder="filter dealer"> </md-form-field> </div> <div> <md-table #table [datasource]="datasource"> <ng-container mdcolumndef="userid"> <md-header-cell *mdheadercelldef> id </md-header-cell> <md-cell *mdcelldef="let row"> {{row.id}} </md-cell> </ng-container> <ng-container mdcolumndef="email"> <md-header-cell *mdheadercelldef> email-id </md-header-cell> <md-cell *mdcelldef="let row"> {{row.email}} </md-cell> </ng-container> <md-header-row *mdheaderrowdef="displayedcolumns"></md-header-row> <md-row *mdrowdef="let row; columns: displayedcolumns;"></md-row> </md-table> </div> </div>
and here ts file
import { component, oninit,elementref, viewchild } '@angular/core'; import { activatedroute } '@angular/router'; import { firebaseapisservice } '../firebase-apis/firebase-apis.service'; import { firebaselistobservable } 'angularfire2/database'; import {datasource} '@angular/cdk/collections'; import {behaviorsubject} 'rxjs/behaviorsubject'; import {observable} 'rxjs/observable'; import 'rxjs/add/operator/startwith'; import 'rxjs/add/observable/merge'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/debouncetime'; import 'rxjs/add/operator/distinctuntilchanged'; import 'rxjs/add/observable/fromevent'; @component({ selector: 'app-season', templateurl: './season.component.html', styleurls: ['./season.component.css'] }) export class seasoncomponent implements oninit { // season: firebaselistobservable<any>; displayedcolumns = ['name', 'mobile', 'email']; datasource: datasourcedealers | null; @viewchild('filter') filter: elementref; constructor(private route: activatedroute, private fireapi: firebaseapisservice) { } ngoninit() { this.route.params.subscribe((param)=>{ this.datasource = new datasourcedealers(this.fireapi,param); observable.fromevent(this.filter.nativeelement, 'keyup') .debouncetime(150) .distinctuntilchanged() .subscribe(() => { if (!this.datasource) { return; } this.datasource.filter = this.filter.nativeelement.value; }); }) } } export class datasourcedealers extends datasource<any> { _filterchange = new behaviorsubject(''); filter(): string { return this._filterchange.value; } set filter(filter: string) { this._filterchange.next(filter); } season: firebaselistobservable<any[]>; input: observable<any>; dealers: any[] = []; constructor(private fireapi: firebaseapisservice,param) { super(); } connect(): observable<any> { this.season = this.fireapi.getdealers('/dealers') this.season.subscribe(dealer => { this.dealers = dealer} ); // return here } disconnect() {} }
i not getting return show data firebase list , show data , able search based on name of dealer.
how can show firebase list data in material m-table
Comments
Post a Comment