如何将在@Input() data
(子组件)中收到的对象传递给dataSource
,我这样做的方式不允许接收它。
我将举例说明我在this link:
@Input() data:PeriodicElement[];
dataSource = new MatTableDataSource<PeriodicElement>(this.data);
@ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
constructor() { }
ngOnInit() {
this.dataSource.paginator = this.paginator;
// console.log(this.dataSource)
}
答案 0 :(得分:1)
定义数据源并使用ngOnInit方法初始化
@Input() data:PeriodicElement[];
dataSource = new MatTableDataSource<PeriodicElement>();
@ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
constructor() { }
ngOnInit() {
this.dataSource = new MatTableDataSource<PeriodicElement>(this.data);
this.dataSource.paginator = this.paginator;
// console.log(this.dataSource)
}
答案 1 :(得分:0)