RXJS:TypeError:this._subscribe 不是函数 [英] RXJS: TypeError: this._subscribe is not a function
问题描述
我正在将 ionic 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
我现在遇到了这个错误:
I'm now experiencing this error:
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 行.
推荐答案
嗯,我找到了问题所在.而且它与 Cordova 无关.
Well, I found the problem. And it's not related to Cordova.
对于遇到此问题的其他人:忘记堆栈跟踪 - 它没用.在我的 this.connectionState$
订阅者的情况下,我试图从一个承诺创建一个 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屋!