RXJS:TypeError:this._subscribe不是函数 [英] RXJS: TypeError: this._subscribe is not a function
问题描述
我正在将离子3.8应用程序迁移到3.9.2。
此次迁移包括对RXJS 5.5的更新
I'm migrating an ionic 3.8 app to 3.9.2. This migration includes an update to RXJS 5.5
我现在遇到此错误:
TypeError:this._subscribe不是函数。 (在'this._subscribe(sink)'中,'this._subscribe'是t的实例)
经过数小时的调试,我发现此代码部分与错误有关:
After hours of debugging, I found out that this code portion is related to the error:
protected observeConnectionState() {
// rxjs/observable/of
of(new Event('disconnect'))
.pipe(
// rxjs/operators/merge
merge(connect$),
merge(disconnect$),
// Map eventname to string (rxjs/operators/map)
map((e: IEvent) => {
return e.eventName == 'connect' ? 'connected' : 'disconnected';
})
)
// Apply to class context
.subscribe((newConnectionState) => {
// this.connectionState$ is a BehaviorSubject
this.connectionState$.next(newConnectionState);
});
}
附加信息
- RXJS代码中有两个地方,我能找到
this._subscribe
: Observable.ts第203行和 Observable.ts第208行。
- There are two places in the RXJS code, were I was able to find
this._subscribe
: Observable.ts Line 203 and Observable.ts Line 208.
推荐答案
好吧,我发现了问题。而且它与Cordova无关。
Well, I found the problem. And it's not related to Cordova.
对于遇到此问题的其他人:
忘记堆栈跟踪 - 它没用。在我的情况下,在 this.connectionState $
的订阅者中,我尝试从promise创建一个Observable。但我做错了。
For other people encountering this problem:
Forget the stack trace - it's useless. In my case in a subscriber of this.connectionState$
I tried to create an Observable from a promise. But I did it wrong.
这是错误的:
import { Observable } from 'rxjs/Observable';
//...
const myObservable$ = Observable.create(myPromise);
这是应该如何做的:
import { fromPromise } from 'rxjs/observable/fromPromise';
// ...
const myObservable$ = fromPromise(myPromise);
这篇关于RXJS:TypeError:this._subscribe不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!