angular - Angular 6 - 参数类型订阅不可分配给参数类型数组
问题描述
试图在表格上显示数据。
智能表组件.ts
export class SmartTableComponent {
clients: Client[];
totalOwed: number;
source: LocalDataSource = new LocalDataSource();
constructor(private clientService: ClientService) {
const data = this.clientService.getClients().subscribe(clients => this.clients = clients);
this.source.load(data); // this line returns the error below
}
这是错误:
参数类型订阅不可分配给参数类型数组
如果我继续我的 ClientService,这就是 getClients() 的作用:
getClients(): Observable<Client[]> {
this.clients = this.clientsCollection.snapshotChanges()
.map(changes => {
return changes.map(action => {
const data = action.payload.doc.data() as Client;
data.id = action.payload.doc.id;
return data;
});
});
return this.clients;
}
那么,如何将订阅转换为数组?
解决方案
而不是分配给数据直接将客户端绑定到源,如下所示,
this.clientService.getClients().subscribe(clients =>{
this.clients = clients;
this.source.load(clients);
});
推荐阅读
- mysql - ErrCode 与“选择进入带有变量的 Outfile” - 混淆权限
- angular - 键入'AngularFireAction
>[]' 不可分配给类型 'Product[]' - android - AlertDialog 未显示在 Android 的 runOnUIThread 中
- performance - 糟糕的 CSS 动画性能 - 没有浏览器绘制
- c# - 计算大量 GPS 坐标之间的成对路由距离
- javascript - 需要在 ReactJS 中的 render() 之前执行函数
- java - 性能调优 - 数据库调用次数
- android - Unity Sprites 图像未更新
- matlab - 将矩阵列转换为单位向量的快速方法
- machine-learning - 为什么要为自适应优化算法设置学习率?