我有的查詢FirebaseListObservable使在離子搜索欄動態搜索的頁面離子。它適用於[email protected]和[email protected]。 升級新版本AngularFire 5.0後我得到FirabaseListObservable的問題還沒有從全新的API出口。AngularFireList是不能分配給輸入「可觀察<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>
然後,我改變了新的API查詢,但你看到下面我不能返回響應,可觀察到的。即時得到錯誤這樣
**消息:「類型「可觀測[]>不是分配給輸入‘可觀測’。 類型'AngularFireAction []'不可分配爲鍵入'響應'。 類型'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;
}
媽ninja'd ...:P –
呵呵'1個min'延遲:d @SurajRao – Sampath
儘管您可能需要更改this.groups'的'申報類型,如果我沒有錯.. –