已安装的依赖项
"@angular/cli": "1.6.6"
"angularfire2": "5.0.0-rc.6",
"firebase": "4.12.1",
"rxjs": "^5.5.10",
"rxjs-compat": "^6.3.3",
我的进口货
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database-deprecated';
import { Observable } from 'rxjs/Observable';
import * as firebase from 'firebase/app';
尝试使用以下方法查询FirebaseDatabase
getMessages(): FirebaseListObservable<ChatMessage[]> {
// Query create list binding
return this.db.list('messages', {
query: { limitToLast: '25' }
});
}
内部版本在控制台中返回以下错误
error TS2345: Argument of type '{ query: { limitToLast: string; }; }'
is not assignable to parameter of type 'FirebaseListFactoryOpts'.
Types of property 'query' are incompatible.
Type '{ limitToLast: string; }' is not assignable to type 'Query'.
Property 'endAt' is missing in type '{ limitToLast: string; }'.
答案 0 :(得分:0)
问题解决了!
将angularFire2更新为最新版本
npm install firebase @angular/fire --save
更改了导入(将FirebaseListObservable替换为AngularFireList)
import { AngularFireDatabase, AngularFireList } from 'angularfire2/database';
接口模型文件中发送的时间已从“日期=新的Date()”更改为“字符串”
去掉了方括号
chatMessages: AngularFireList<ChatMessage>;
getMessages(): AngularFireList<ChatMessage> {
// changed the query since the AngularFireList does it differently.
return this.db.list('messages', ref => ref.orderByKey().limitToLast(25));
}