import { Component, Input } from '@angular/core'; @Component({ selector: 'app-table', template: `
{{column.name}}
{{ getDataByIdentifiers(item, column.identifiers) ? (getDataByIdentifiers(item, column.identifiers) | date) : "ongoing" }}
{{ getDataByIdentifiers(item, column.identifiers) }}
`, styleUrls: ['./table.component.css'] }) export class TableComponent { @Input() columns: { name: string, identifiers: string[], type?: TableCellType }; @Input() items: Object[]; @Input() loading: boolean; TableCellType = TableCellType; constructor() { } getDataByIdentifiers(object, identifiers) { return identifiers.reduce((prev, curr) => !!prev ? prev[curr] : prev, object); } } export enum TableCellType { DATE, LINK }