rxjs-TypeError:Object(...)不是函数

时间:2019-01-04 08:02:59

标签: angular rxjs

我有基于angular 6.10和rxjs 6.3的应用程序。我也有问题:(

这是我的代码:

  public keyUp = new Subject<string>();
const observable = this.keyUp
      .pipe(
         map(value => (event.target as HTMLInputElement).value),
         debounceTime(300),
         distinctUntilChanged(),
         flatMap((search) => {
           return of(search).pipe(delay(300));
         }),
      )
      .subscribe((data) => {
        this.filter = data;
        this.onFilterChange(this.filter);
      });

此代码由我从rxjs 5.5.6合并而来-不幸的是,我不记得较早的版本。这是实际版本错误:

ERROR TypeError: Object(...) is not a function
    at MergeMapSubscriber.eval [as project] (framework.js:232)
    at MergeMapSubscriber._tryNext (mergeMap.js:128)
    at MergeMapSubscriber._next (mergeMap.js:118)
    at MergeMapSubscriber.Subscriber.next (Subscriber.js:92)
    at DistinctUntilChangedSubscriber._next (distinctUntilChanged.js:104)
    at DistinctUntilChangedSubscriber.Subscriber.next (Subscriber.js:92)
    at DebounceTimeSubscriber.debouncedNext (debounceTime.js:101)
    at AsyncAction.dispatchNext (debounceTime.js:117)
    at AsyncAction._execute (AsyncAction.js:119)
    at AsyncAction.execute (AsyncAction.js:94)

1 个答案:

答案 0 :(得分:0)

对于我来说,此错误是在我的导入不正确时发生的。

我的导入就像:

import { tap } from 'rxjs/operators';

正确的版本是:

import { tap } from 'rxjs/operators/tap';

请检查如何导入mergeMap运算符。