AngularFire2 typings: “Property 'take' does not exist on type 'FirebaseObjectObservable<any>'”

喜欢而已 提交于 2020-01-04 01:14:06

问题


I've updated my ionic app from beta 11 to rc0. So it means I've switched from typescript 1.8 to 2.

I've configured AngularFire2 according to this site Getting Started with Ionic 2 RC0, Firebase 3 + AngularFire 2

I had this line of code working:

this.af.database.object(`comments/${commentId}`).take(1).subscribe({
    data => console.log(data)
});

But now getting this error

error TS2339: Property 'take' does not exist on type 'FirebaseObjectObservable'.

Any ideas on what's going on? How can I solve this?


回答1:


For more recents versions of rxjs (v6) and angularfire (v5), the syntax I used is :

import { take } from 'rxjs/operators'

...

this.afAuth.authState.pipe(take(1)).subscribe(user => {
  ...
})



回答2:


Posting user @codedesignr's answer from above so this question can have an official solution:

Import the rxjs take operator using: import 'rxjs/add/operator/take';




回答3:


If your angular version is 6 and above.

use below:

import { take, map } from "rxjs/operators";

Install - npm install --save rxjs-compat

Also user pipe with other functions(Take, Map).

timer(0, 10) .pipe(take(1000)) .pipe(map(() => x));



来源:https://stackoverflow.com/questions/39808394/angularfire2-typings-property-take-does-not-exist-on-type-firebaseobjectobs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!