I have a simple table that shows static data, however, I have issues for showing it via input.
The question is how can I pass the data to the material2 table using item input.
export class InvoiceItemComponent implements OnInit {
displayedColumns = ['id', 'description', 'amount', 'taxGroup'];
exampleDatabase = new ExampleDataBase();
dataSource: ExampleDataSource | null;
@Input() item;
constructor() {}
ngOnInit() {
console.log(this.exampleDatabase.data);
this.dataSource = new ExampleDataSource(this.exampleDatabase);
}
}
export class ExampleDataBase {
dataChange: BehaviorSubject<any> = new BehaviorSubject([]);
get data(): InvoiceItem[] {
return [ // works fine with static data, cannot figure out how to pass it via @Input() item which is the required data
{
id: 1,
description: 'your desc here',
amount: 20,
taxAmount: 20,
taxGroup: {
id: 1,
name: 'tax group name'
}
},
];
}
constructor() {
this.dataChange.next(this.data);
}
}
export class ExampleDataSource extends DataSource<any> {
constructor(private _exampleDatabase: ExampleDataBase) {
super();
}
/** Connect function called by the table to retrieve one stream containing the data to render. */
connect(): Observable<InvoiceItem[]> {
console.log(this._exampleDatabase.dataChange);
return this._exampleDatabase.dataChange;
}
disconnect() {}
}