你如何设置dataAccessor
在 mat-text-column
从HTML?该文档不包含任何示例。注意dataAccessor
的签名是一个函数:
dataAccessor: (data: T, name: string) => string;
最佳答案
“ _renderPrice ”在以下示例中用作 dataAccessor 函数。该函数接收一个由 dataSource 定义的类型的对象作为参数,并且必须返回一个字符串。它为表中的每一行调用一次。
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'app-orderpositions',
template: `
<table mat-table [dataSource]="positions">
<mat-text-column name="price" justify="end"
[headerText]="'BESTELLUNG.POSITIONEN.PREIS' | translate"
[dataAccessor]="_renderPrice">
</mat-text-column>
<tr mat-header-row *matHeaderRowDef="_displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: _displayedColumns;"></tr>
</table>
`
})
export class OrderpositionsComponent {
@Input()
positions: Orderposition[];
readonly _displayedColumns: string[] = ['price'];
_renderPrice(position: Orderposition): string {
return `${position.price} EUR`;
}
}
希望这可以帮助。
关于angular - 如何在 Angular 中使用 mat-text-column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59495882/