聊天应用程序内置在 Angular 6 x AngularFire2 投掷错误



已安装的依赖项

"@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; }'.

问题已解决!

将角度火2更新为最新版本

npm install firebase @angular/fire --save

更改了导入(FirebaseListObservable替换为AngularFireList(

import { AngularFireDatabase, AngularFireList } from 'angularfire2/database';

更改了接口模型文件中的时间从"日期 = 新日期(("发送到"字符串">

删除了方括号

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

最新更新