rxjs - TypeError:Object(…)不是一个函数
2019-01-04
2820
我有一个基于 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个回答
对我来说,当我的导入不正确时会发生此错误。
我的导入如下:
import { tap } from 'rxjs/operators';
正确的版本是:
import { tap } from 'rxjs/operators/tap';
请检查您如何导入
mergeMap
运算符。
Maryam Saeidi
2019-06-14