带有 Observables 的 AngularFire2 没有捕捉到 $ref 属性
AngularFire2 with Observables doesn't catch $ref property
所以我开始使用 AngularFire2(版本 4.0.0-rc.1)并遇到了这个问题:
getWishlist$(): FirebaseListObservable<{}> {
return <FirebaseListObservable<{}>>this.store.select(getFirebaseUID)
.filter(res => res.isAuthenticated)
.map(res => res.UserUUID)
.switchMap(uid => this.db.list(`/wishlist/${uid}/products`));
}
所以在 switchMap 运算符之后它应该 return 我来自 this.db.list()
的原始 Observable,它是 FirebaseListObservable,但它没有发生,我的下一个代码在运行时有错误。
this.accountService.getWishlist$().$ref
.orderByChild('pk').equalTo(designer.pk).once('value', (data) => {
if (!data.exists()) {
this.accountService.getWishlist$().push(designer);
}
})
错误是:
Cannot read property 'orderByChild' of undefined
我做错了什么?
我回答了通过 repo issue:
提出的类似问题
That isn't how switchMap
- and RxJS, in general - works. The observable returned by an operator depends upon the observable upon which the operator is called. Said observable can implement lift
to return an observable instance of the same type.
The AngularFire2 observables implement lift
- see here and here - but that makes no difference in the situation you have described, ...
从您的 switchMap
调用返回的 observable 是从 this.store.select
中提取的 observable - 而不是从 this.db.list
.
所以我开始使用 AngularFire2(版本 4.0.0-rc.1)并遇到了这个问题:
getWishlist$(): FirebaseListObservable<{}> {
return <FirebaseListObservable<{}>>this.store.select(getFirebaseUID)
.filter(res => res.isAuthenticated)
.map(res => res.UserUUID)
.switchMap(uid => this.db.list(`/wishlist/${uid}/products`));
}
所以在 switchMap 运算符之后它应该 return 我来自 this.db.list()
的原始 Observable,它是 FirebaseListObservable,但它没有发生,我的下一个代码在运行时有错误。
this.accountService.getWishlist$().$ref
.orderByChild('pk').equalTo(designer.pk).once('value', (data) => {
if (!data.exists()) {
this.accountService.getWishlist$().push(designer);
}
})
错误是:
Cannot read property 'orderByChild' of undefined
我做错了什么?
我回答了通过 repo issue:
提出的类似问题That isn't how
switchMap
- and RxJS, in general - works. The observable returned by an operator depends upon the observable upon which the operator is called. Said observable can implementlift
to return an observable instance of the same type.The AngularFire2 observables implement
lift
- see here and here - but that makes no difference in the situation you have described, ...
从您的 switchMap
调用返回的 observable 是从 this.store.select
中提取的 observable - 而不是从 this.db.list
.