Angular 如何将Observable转换为MatTableDataSource?

Angular 如何将Observable转换为MatTableDataSource?,angular,observable,Angular,Observable,我有下面的代码,但不知道如何将可观察的“posts”从firebase转换为MatTableDataSource“postsTable” 因为我想将mat table数据源更改为MatTableDataSource,所以使用mat paginator 我试图在定义中有一个新的MatTableDataSource,或者在firestore返回的数据映射后创建它,但不起作用 export interface Post { title: string; category: string

我有下面的代码,但不知道如何将可观察的“posts”从firebase转换为MatTableDataSource“postsTable”

因为我想将mat table数据源更改为MatTableDataSource,所以使用mat paginator

我试图在定义中有一个新的MatTableDataSource,或者在firestore返回的数据映射后创建它,但不起作用

export interface Post {
    title: string;
    category: string;
    image: string;
    content: string;
    updateAt: firebase.firestore.FieldValue;
}
export interface PostID extends Post { id: string; }

export class PostsViewComponent implements OnInit {

    private postCollection: AngularFirestoreCollection;
    posts: Observable<PostID[]>;
    postsTable = new MatTableDataSource();

    ngOnInit() {
        this.postCollection = this.angularFirestore.collection('posts');
        this.posts = this.postCollection.snapshotChanges().pipe(
            map(actions => actions.map(a => {
                const data = a.payload.doc.data() as PostID;
                data.id = a.payload.doc.id;
                return data;
            }))
        );
     }

}
导出接口Post{
标题:字符串;
类别:字符串;
图像:字符串;
内容:字符串;
updateAt:firebase.firestore.FieldValue;
}
导出接口PostID扩展Post{id:string;}
导出类PostsViewComponent实现OnInit{
私人收藏:AngularFirestoreCollection;
职位:可观察;
postsTable=新MatTableDataSource();
恩戈尼尼特(){
this.postCollection=this.angularFirestore.collection('posts');
this.posts=this.postCollection.snapshotChanges().pipe(
map(actions=>actions.map(a=>{
const data=a.payload.doc.data()作为PostID;
data.id=a.payload.doc.id;
返回数据;
}))
);
}
}

返回任何数据;你能试试这个吗?你能创造一个闪电战吗?