处理管道和订阅firebase Query对象的类似方法是什么?

Att*_*s29 5 javascript firebase firebase-realtime-database angular

我在Angular中有一个服务,使用以下方法从Firebase获取数据:

getMatchesFiltered(matchId: string, filter: string, sortDirection: string, pageIndex: number, pageSize: number){
    return this.db.object('/matches');
  }
Run Code Online (Sandbox Code Playgroud)

它返回一个火力点可观察到,我可以申请pipesubscribe,例如,

this.dbService.getMatchesFiltered(matchId, filter, sortDirection, pageIndex, pageSize).pipe(
                    catchError(()=> of([])),
                    finalize(()=>this.loadingMatches.next(false))
                  )
                  .subscribe(matches => {
                    let results = [];
                    let json_data = matches;
                    for(var i in json_data){
                      if(json_data[i].matchDeets){
                        results.push([i, json_data[i].matchDeets][1]);
                      }
                    }
                    this.matchesSubject.next(results);
                  });
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试从数据库服务返回一个Query时,返回的对象不再是Observable:

getMatchesFiltered(matchId: string, filter: string, sortDirection: string, pageIndex: number, pageSize: number){
    let ref = firebase.database().ref("/matches");
    return ref.limitToFirst(pageSize);
  }
Run Code Online (Sandbox Code Playgroud)

src/app/matchDataSource.model.ts(29,106)中的错误:错误TS2339:类型'Query'上不存在属性'pipe'

关于如何以类似于observable的方式处理查询,文档似乎不是很明确.

例如,我可以在收到DataSnapshot之后做一些事情:

ref.orderByKey().endAt("pterodactyl").on("child_added", function(snapshot) {
  console.log(snapshot.key);
});
Run Code Online (Sandbox Code Playgroud)

但这是否意味着我必须.on("child_added", function(snapshot) {});在我的组件中添加该部分,而不是将其保存在服务中?

所以,我想我有以下问题:

  1. 我不知道如何正确地划分/封装它.

  2. 我不知道如果我必须求助于如何处理pipe命令对component.ts文件中的查询执行的操作.

  3. 我不知道我是否遗漏了一些非常容易和直接的方法来使查询的行为类似于Observable.

如果需要,很高兴从github提供工作示例.

Rob*_*hof 2

是否可以将其放入 Observable 中:

Observable.create(function(observer) {
    ref.orderByKey().endAt("pterodactyl").on("child_added", snapshot => 
    {
        observer.next(snapshot.key);
    });
};
Run Code Online (Sandbox Code Playgroud)