Angular 角4分量绑定函数
我正在制作一个自定义组件来构建一个表Angular 角4分量绑定函数,angular,Angular,我正在制作一个自定义组件来构建一个表 export class TableComponent implements OnChanges { @Input() records: any[]; @Input() caption: string; @Input() config: TableConfig[]; } export class TableConfig { basePath: string; actions?: object[]; } //Acti
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 }
*/
我只需要在需要表格的地方调用我的组件
<my-table
[records]="entities"
[caption]="Table"
[config]="myConfig">
</my-table>
但是当我试图在我的表格模板上打电话时,它不起作用
<button class="btn btn-default" *ngFor="let action of config.actions" (click)="action.onClick()">
<span class="{{action.icon}}"></span>
</button>
您应该使用类型安全运算符吗?因为DOM甚至在检索数据之前就呈现了
<button class="btn btn-default" *ngFor="let action of config?.actions"
(click)="action.onClick()">
<span class="{{action?.icon}}"></span>
</button>
你有什么错误吗??如果是这样,那是什么?我想这不是问题所在,但现在我重写了代码并开始工作…所以我会接受你的答案,因为这个问题?诀窍:D
<button class="btn btn-default" *ngFor="let action of config?.actions"
(click)="action.onClick()">
<span class="{{action?.icon}}"></span>
</button>
<span *ngIf="config.actions.length > 0">
<button class="btn btn-default" *ngFor="let action of config.actions" (click)="action.onClick()">
<span class="{{action.icon}}"></span>
</button>
</span>