角度:类型 'Observable<Order[]>' 的参数不可分配给类型 'Observable<Order[]>[]' 的参数



我正在尝试使用mat-paginator,在这里我需要将firebase集合中的数据分配给MatTableDataSource。我想做的是:

private orderCollection: AngularFirestoreCollection<Order>;
public bookings: Observable<Order[]>;
@ViewChild(MatPaginator) paginator: MatPaginator;  
@ViewChild(MatPaginator) dataSource: MatTableDataSource<Observable<Order[]>>;

在构造函数中:

this.orderCollection = this.afs.collection<Order>('bookings');
this.bookings = this.orderCollection.valueChanges();
this.dataSource = new MatTableDataSource(this.bookings);

现在我得到的编译错误像:

(property) OrderListComponent.bookings: Observable<Order[]>
Argument of type 'Observable<Order[]>' is not assignable to 
parameter of type 'Observable<Order[]>[]'.
Type 'Observable<Order[]>' is missing the
following properties from type 'Observable<Order[]>[]': length, pop,
> push, concat, and 28 more.

注意:如果我定义dataSource: MatTableDataSource<<Order[]>;结果就是简单的Order[]

但是如果我定义dataSource: MatTableDataSource<Observable<Order[]>>;这在最后附加了一个CCD_ 5;比如-"可观察<订单[]>[]'

因此,如果有一种方法可以定义不附加[]的可观测

那么我相信这个问题会得到解决。

public bookings: Observable<Order[]>;更改为public bookings: Observable<Order[]>[];并尝试。

相关内容

最新更新