RxJS已更新,类型“ typeof Observable”上不存在属性“合并”

时间:2018-10-14 13:24:16

标签: angular rxjs material rxjs6

我更新了材质角度项目,以在表格中包括一个可扩展的详细信息行。为此,我需要升级到rsjx 6。现在,我收到以下错误。我对angular完全陌生,所以很遗憾,我不知道如何解决这个问题。

Property 'merge' does not exist on type 'typeof Observable'.

任何人都可以帮助解决此错误吗?

app.component.ts

  /** Connect function called by the table to retrieve one stream containing the data to render. */
  connect(): Observable<Track[]> {
    // Listen for any changes in the base data, sorting, filtering, or pagination
    const displayDataChanges = [
    this._exampleDatabase.dataChange,
    this._sort.sortChange,
    this._filterChange,
    this._paginator.page
    ];

    this._exampleDatabase.getAllTracks();

    return Observable.merge(...displayDataChanges).map(() => {
      // Filter data
      this.filteredData = this._exampleDatabase.data.slice().filter((track: Track) => {
        const searchStr = (track.id + track.title + track.artist + track.year + track.comment + track.path).toLowerCase();
        return searchStr.indexOf(this.filter.toLowerCase()) !== -1;
      });

      // Sort filtered data
      const sortedData = this.sortData(this.filteredData.slice());

      // Grab the page's slice of the filtered sorted data.
      const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
      this.renderedData = sortedData.splice(startIndex, this._paginator.pageSize);
      return this.renderedData;
    });
  }

2 个答案:

答案 0 :(得分:2)

从版本6开始,以下列方式导入了静态merge

import {merge} from 'rxjs'

然后将其用作:

merge(...)

答案 1 :(得分:0)

在旧版本的rxjs中,您使用Observable.merge(...array).map(() => {});。 对于新版本,即 rxjs 6 + ,您必须使用以下语法:

import { merge } from 'rxjs';
import { map } from 'rxjs/operators';

merge(...array).pipe(
  map(...),
  ...
);