2017-10-11 25 views
5

Mam stronę jońską, która wysyła zapytanie do FirebaseListObservable, aby przeprowadzić dynamiczne wyszukiwanie na pasku wyszukiwania jonów. Działa dobrze z [email protected] i [email protected] Po aktualizacji nowego wydania AngularFire 5.0 pojawia się problem związany z tym, że FirabaseListObservable nie wyeksportował nowego Api.AngularFireList nie można przypisać "Observable <Response>

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(); 
 
    } 
 

 
}
<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>

Potem zmienił kwerendy z nowego API, ale nie mogę wrócić odpowiedź jako obserwowalne jak widać poniżej. Otrzymuję komunikat o błędzie podobny do tego: ** "Type" Observable []> "nie można przypisać" Observable ". Typ 'AngularFireAction []' nie można przypisać "Response". W typie "AngularFireAction []" brakuje właściwości typu ". **

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; 
 
    }

Odpowiedz

1

Trzeba użyć .valueChanges() jak pokazano below.Here jest doc.

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; 
} 
+0

przeklętej ninja'd ..: p –

+0

Hehe '1 min' opóźnienie: D @SurajRao – Sampath

+0

Chociaż być może będziesz musiał zmienić typ deklaracji' this.groups' jeśli się nie mylę .. –

4

W celu uzyskania Observable<Response> z AngularFireList z 5,0 r użycie valueChanges() funkcja.

Sprawdź zmianę here.

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

Jeśli chcesz zapisać wystąpienie this.afDatabase.list() w this.groups, to będzie AngularFireList zamiast FirebaseListObservable.

0

W Angularfire2 5.0 lub lepiej, Jeśli potrzebujesz zaobserwowania listy z kwerendy trzeba użyć AngularFireAction jak widać poniżej

import { Component } from '@angular/core'; 
 
import { IonicPage, NavParams, ViewController} from 'ionic-angular'; 
 
import {AngularFireDatabase, AngularFireAction} from 'angularfire2/database'; 
 
import { Observable } from 'rxjs/Observable'; 
 
import {EmptyObservable} from 'rxjs/observable/EmptyObservable'; 
 
// import { Response } from '@angular/http'; 
 
import * as firebase from 'firebase/app'; 
 

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

 
    
 
    groups: Observable<AngularFireAction<firebase.database.DataSnapshot>[]>; 
 

 
    
 

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

 
- 
 

 
    getItems = (ev: any) : Observable<AngularFireAction<firebase.database.DataSnapshot>[]> => { 
 
    if(!ev.data){ 
 
     return this.groups = new EmptyObservable(); 
 
    } 
 
    this.groups = this.afDatabase.list('/Groups', ref => ref.orderByChild('namelower').startAt(ev.target.value).endAt(ev.target.value + '\uf8ff')).valueChanges(); 
 
    // this.groups = this.groupsRef.valueChanges(); 
 
     return this.groups; 
 
    } 
 

 
    chooseGroups(item:any){ 
 
    // this.product.push({key:item.$key, name:item.name, price:item.price, quantity:1 }); 
 
     
 
    this.viewCtrl.dismiss(item); 
 
    // console.log(this.product); 
 
    } 
 

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

 
}

Powiązane problemy