【发布时间】:2018-07-15 20:42:59
【问题描述】:
尝试在表格上显示数据。
Smart-table-component.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.source.load
标签: angular firebase google-cloud-firestore