Angular-material2, how can I add new data to the md-table data file?

when i add a new item i want the new item to be added at the beginning of the md-table

dataSouce.

Also known as: datas.unshift(newItem)

. But md-table

uses BehaviorSubject

for rxjs

, I don't know how.

export class DeptDataSource extends DataSource<any> {
  constructor(
    private deptService: DeptService
  ) {
    super();
  }

  connect(): Observable<any[]> {
    const displayDataChanges = [
      this.deptService.dataChange
    ];
    return Observable.merge(...displayDataChanges).map(() => {
      const data = this.deptService.getDeptsData();
      const { t } = <any>data;

      return t;
    });
  }

  disconnect(): void {
    this.deptService.dataChange.complete();
  }
}

      

+3


source to share





All Articles