AngularFireList不能分配给'Observable <Response>类型

Ser*_*nal 9 firebase firebase-realtime-database angularfire2 ionic3 angular

我有一个Ionic页面,它查询FirebaseListObservable以在ion-searchbar上进行动态搜索.它适用于Angularfire2@4.0.0-rc.0和firebase@4.5.0.在升级新版本AngularFire 5.0后,我遇到了一个关于FirabaseListObservable没有从新Api导出的问题.

import { Component } from '@angular/core';
import { IonicPage,  NavParams, ViewController } from 'ionic-angular';
import {AngularFireDatabase, FirebaseListObservable} from 'angularfire2/database';
import { Observable} from 'rxjs';
import { Response } from '@angular/http';

@IonicPage()
@Component({
  selector: 'page-modal-groups',
  templateUrl: 'modal-groups.html'
})
export class ModalGroupsPage {

  groups: FirebaseListObservable<any>;

  constructor(public navParams: NavParams,
    public viewCtrl:ViewController,
    public afDatabase: AngularFireDatabase) {
  }

  getItems = (ev: any) : Observable<Response> =>  {
    
    this.groups =  this.afDatabase.list('/Groups', {
       query:{
         orderByChild: 'namelower',
         startAt: (ev.target.value),
         endAt: (ev.target.value + '\uf8ff')
       }
      }
     );


     return this.groups;
  }

  chooseGroups(item:any){
      
    this.viewCtrl.dismiss(item); 
    // console.log(this.product);
  }

  closeModal(){
    this.viewCtrl.dismiss(); 
  }

}
Run Code Online (Sandbox Code Playgroud)
<ion-header>

  <ion-navbar>
    <ion-title>Grup Seç</ion-title>
    <ion-buttons end>
      <button ion-button color="danger" (click)="closeModal()" >
        Kapat
      </button>
    </ion-buttons>
  </ion-navbar>

</ion-header>


  <ion-content padding>
  <ion-searchbar (ionInput)="getItems($event)"></ion-searchbar>
  <ion-list>
    <ion-item  *ngFor="let item of groups | async" (click)="chooseGroups(item)">
      {{ item.name }}
    </ion-item>
  </ion-list>
  <!--<button ion-item  *ngFor="let item of products | async" (click)="chooseProduct(item)">
  {{item.name}}
</button>-->
</ion-content>
Run Code Online (Sandbox Code Playgroud)

然后我用新的api更改了查询但是我不能将响应作为一个observable返回,如下所示.我得到这样的错误

**消息:'类型'Observable []>'不能分配给'Observable'类型.类型'AngularFireAction []'不能分配给'Response'类型.'AngularFireAction []'类型中缺少属性'type'.**

import { Component } from '@angular/core';
import { IonicPage,  NavParams, ViewController } from 'ionic-angular';
import {AngularFireDatabase, AngularFireAction} from 'angularfire2/database';
import { Observable, BehaviorSubject} from 'rxjs';
import { Response } from '@angular/http';
/**
 * Generated class for the ModalGroupsPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-modal-groups',
  templateUrl: 'modal-groups.html',
})
export class ModalGroupsPage {

  

  items: Observable<AngularFireAction<firebase.database.DataSnapshot>[]>;
  group: BehaviorSubject<any>;

  constructor(public navParams: NavParams,
    public viewCtrl:ViewController,
    public afDatabase: AngularFireDatabase) {
  }

  

  getItems = (ev: any) : Observable<Response> =>  {
    this.group = new BehaviorSubject(ev);

    this.items = this.group.switchMap(name =>
    
      this.afDatabase.list('/Groups', ref => name ? ref.orderByChild('namelower').startAt(ev.target.value).endAt(ev.target.value + '\uf8ff') : ref
   
     ).snapshotChanges());
  

     return this.items;
  }
Run Code Online (Sandbox Code Playgroud)

Sur*_*Rao 6

为了Observable<Response>5.0以后的版本中从AngularFireList 获取,请使用valueChanges()function。

此处检查更改。

return this.afDatabase.list('/Groups', {
       query:{
         orderByChild: 'namelower',
         startAt: (ev.target.value),
         endAt: (ev.target.value + '\uf8ff')
       }
      }
     ).valueChanges();
Run Code Online (Sandbox Code Playgroud)

如果要保存this.afDatabase.list()in 的实例this.groups,它将AngularFireList代替FirebaseListObservable


Sam*_*ath 1

您需要.valueChanges()如下所示使用。这是文档

  groups: AngularFireList<any>;

  constructor(){}

getItems = (ev: any) : AngularFireList<any> {
  this.groups =  this.afDatabase.list('/Groups', {
       query:{
         orderByChild: 'namelower',
         startAt: (ev.target.value),
         endAt: (ev.target.value + '\uf8ff')
       }
      }
     ).valueChanges();

    return this.groups;
}
Run Code Online (Sandbox Code Playgroud)