I'm making a custom component to build a table.
export class TableComponent implements OnChanges {
@Input() records: any[];
@Input() caption: string;
@Input() config: TableConfig[];
}
export class TableConfig {
basePath: string;
actions?: object[];
}
//Actions example
/*
action = { icon: "", description: "", onClick: thisMustReceiveAFunction }
*/
I just call my component where I want the table
<my-table
[records]="entities"
[caption]="Table"
[config]="myConfig">
</my-table>
And initialize my config inside my component caller
myConfig: TableConfig = {
basePath: "users",
actions: [
{
icon: "glyphicon glyphicon-pencil",
description: "edit",
onClick: this.MyEditFunction
},
{
icon: "glyphicon glyphicon-trash",
description: "delete"
onClick: this.MyDeleteFunction
}
]
};
MyEditFunction(): void { console.log('edit clicked'); }
MyDeleteFunction(): void { console.log('delete clicked'); }
But when I try to make a call at my table template, it doesnt work.
<button class="btn btn-default" *ngFor="let action of config.actions" (click)="action.onClick()">
<span class="{{action.icon}}"></span>
</button>