我正在尝试在有角度的材质表中显示Firebase中的某些项目。我将商品(汽车)带到一个数组中,然后在数据源中发送该数组,但从未显示商品。这是我的代码:
ngOnInit() {
this.dbService.getCars().subscribe((cars) =>{
this.cars.length = 0;
cars.map((car:any)=>{
this.cars.push(car.payload.doc.data());
this.dataSource = new MatTableDataSource(this.cars);
});
});
}
服务中还有getCars:
getCars(){
return this.dbFirestore.collection('cars').snapshotChanges();
}
答案 0 :(得分:0)
在更新数据后尝试实施变更检测。
constructor(private changeRef : ChangeDetectorRef) { }
this.dbService.getCars().subscribe((cars) =>{
this.cars.length = 0;
cars.map((car:any)=>{
this.cars.push(car.payload.doc.data());
this.dataSource = new MatTableDataSource(this.cars);
});
//This line updates the UI with new changes in data
this.changeRef.detectChanges();
});