import { Component , ComponentFactoryResolver , HostBinding , Input , OnInit , ViewChild , ViewContainerRef } from '@angular/core' ; import { Column } from '../../table.types' ; @ Component ( { selector : 'td[table-cell]' , templateUrl : './table-cell.component.html' , styleUrls : [ './table-cell.component.scss' ] } ) export class TableCellComponent < T > { @ HostBinding ( 'class' ) private cssClasses : Array < string > ; @ HostBinding ( 'class' ) private cellClasses : Array < string > ; /**
     * When column is hidden, add css class hidden to cell.
     */ @ HostBinding ( 'class.hidden' ) @ Input ( ) public hidden : boolean = false ; /**
     * Row index which this cell is in.
     */ @ Input ( ) rowIndex : number ; public data : any ; public column : Column ; @ Input ( 'column' ) public set Column ( col ) { this . column = col ; this . hidden = this . column . hidden ; this . cssClasses = this . column . cssClasses || [ ] ; this . cellClasses = this . column . cellClasses || [ ] ; } public item : T ; @ Input ( 'item' ) public set Item ( item ) { this . item = item ; if ( this . column . data ) { const cellData = TableCellComponent . resolve ( this . column . data , this . item ) ; if ( this . column . render ) { this . data = this . column . render ( cellData , this . item , this . column , this . rowIndex ) ; } else { this . data = cellData ; } } } param path param obj param separator static resolve ( path , obj , separator = '.' ) { const properties = Array . isArray ( path ) ? path : path . split ( separator ) ; return properties . reduce ( ( prev , curr ) => prev && prev [ curr ] , obj ) ; } }