无法在 angularFire 应用程序中使用查询
unable to use query in angularFire application
我正在创建一个 AngularFire 应用程序,这是我 app.component.ts:
中的代码
import { Component } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable } from
'angularfire2/database';
import { AngularFireAuth } from 'angularfire2/auth';
import { Observable } from 'rxjs/Observable';
import * as firebase from 'firebase/app';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
user: Observable<firebase.User>;
items: FirebaseListObservable<any[]>;
msgVal: string = '';
constructor(public afAuth: AngularFireAuth, public af: AngularFireDatabase) {
this.items = af.list('/messages', {
query: {
//I am using a limitToLast: 50 here, but isn't working.
}
});
this.user = this.afAuth.authState;
}
}
问题是它没有编译,我的文本编辑器(vs 代码)返回以下错误:
当我将鼠标悬停在 query: {
上时:[ts]
Argument of type '{ query: { limitToLast: number; }; }' is not assignable to parameter of type 'QueryFn'. Object literal may only specify known properties, and 'query' does not exist in type 'QueryFn'.
我好像找不到问题,为什么会这样?
我猜你使用的是最新的 angularfire2 和 firebase 版本,因为我遇到了同样的异常。他们在最新更新中改变了几件事。这里有一个link到angularfire2 latest docs.
对于你的情况,你可以这样解决:
constructor(public afAuth: AngularFireAuth, public af: AngularFireDatabase) {
this.items = af.list('/messages', ref => ref.orderByKey(true).limitToLast(50));
});
this.user = this.afAuth.authState;
}
我正在创建一个 AngularFire 应用程序,这是我 app.component.ts:
中的代码import { Component } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable } from
'angularfire2/database';
import { AngularFireAuth } from 'angularfire2/auth';
import { Observable } from 'rxjs/Observable';
import * as firebase from 'firebase/app';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
user: Observable<firebase.User>;
items: FirebaseListObservable<any[]>;
msgVal: string = '';
constructor(public afAuth: AngularFireAuth, public af: AngularFireDatabase) {
this.items = af.list('/messages', {
query: {
//I am using a limitToLast: 50 here, but isn't working.
}
});
this.user = this.afAuth.authState;
}
}
问题是它没有编译,我的文本编辑器(vs 代码)返回以下错误:
当我将鼠标悬停在 query: {
上时:[ts]
Argument of type '{ query: { limitToLast: number; }; }' is not assignable to parameter of type 'QueryFn'. Object literal may only specify known properties, and 'query' does not exist in type 'QueryFn'.
我好像找不到问题,为什么会这样?
我猜你使用的是最新的 angularfire2 和 firebase 版本,因为我遇到了同样的异常。他们在最新更新中改变了几件事。这里有一个link到angularfire2 latest docs.
对于你的情况,你可以这样解决:
constructor(public afAuth: AngularFireAuth, public af: AngularFireDatabase) {
this.items = af.list('/messages', ref => ref.orderByKey(true).limitToLast(50));
});
this.user = this.afAuth.authState;
}