AngularFire firebase cloud function return 取值问题

AngularFire firebase cloud function return value problem

我对 AngularFire 有疑问,因为在他们的 github (Documentation) 中它说 returns 一个 Observable。

这是 Whosebug 上的新帐户,所以我无法在此处嵌入图像。

code problem

但问题是我无法订阅 Observable。

我的猜测是它与

有关
(data: any) => Observable<any>;

因为当我尝试将 httpCallReleaseUser 变量类型定义为 Observable 时。我收到一条错误消息,告诉我它没有订阅和其他一些方法。

now with type definition

如果这就是问题所在

有什么区别
Observable<any>

(data: any) => Observable<any>;

你的定义是错误的。正如@Nelles 所指出的,您正在执行一项功能,但它并没有按照您的意愿执行。你可能想要一些简单的东西,比如: data:Observable<any>; 这表示您的变量是可观察类型。

你可能需要获取不同格式的数据,甚至可以使用接口。也许像下面这样。

export class foo {
    private data:Observable<myInterface[]>;

    constructor(
        @Inject(AngularFireDatabase) protected AfDb: AngularFireDatabase,
    ) { }

    public get():Observable<myInterface[]> // Return an array of myInterface items as an observable. Note that the data in firebase needs to match myInterface, but fields will be supported automatically
    {
        data = this.AfDb.list<myInterface[]>('firebasetable').valueChanges()
        return data;
    }
}

Observable() => Observable的区别在于后者是一个输出Observable的函数。

AngularFireFunctions 具有签名 httpsCallable(name:string) => (data:any) => Observable<any>,这意味着您必须调用它两次,首先使用函数名称,然后再次使用要传递给函数的数据。

functions.httpsCallable('fn-name')({ ... your data here or empty })