我在StackBlitz上设置了 Angular webapp 的一部分。
在其中,我正在尝试使用来自具有过滤、分页和排序功能的 firebase 的数据来实现 mat-table 的最佳方法。
VideoDataSource
最后在'./videoDataSource.model.ts'中编写了一个实现MatTableDataSource接口的类。其中,有一个方法叫做loadMatches()
. 这是一种async
方法:
async loadMatches(): Promise<any>{
console.log("loadMatches entered");
let results = await this.dbService.getMatchesV2().toPromise();
console.log("results in loadMatches");
console.log(results);
let dbMatches = results.map(Match.fromJson);
return dbMatches.toPromise();
}
其中dbService.getMatchesV2()
又来自注入的服务,如下所示:
getMatchesV2(){
return this.db.list<Match>('/matches').valueChanges();
}
其中 db 是类型数据库服务的参数AngularFireDatabase
。
app.component.ts 中的loadMatches()
调用如下所示:
this.data = await this.dataSource.loadMatches();
其中 data 是AppComponent
类型的参数Match[]
。
我收到错误“意外的严格模式保留字”,引用了没有任何意义的行号(在 app.module.ts 中;我想这是一个编译后的行号?)。问题在我尝试实现 async/await 后立即开始。DatabaseService 主要处理 Observables,但我认为.toPromise()
这足以解决问题。关于发生了什么的任何见解?提前谢谢了!