angular - 如何在 Angular 中使用 mat-text-column

标签 angular angular-material

你如何设置dataAccessormat-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/

相关文章:

javascript - 如何在 angular 2.0 中创建拖动属性指令?

angular - 使用 mat paginator 方法 firstPage() 进行功能单元测试

angular - 使用 Angular Material 核心主题的 Angular 应用程序中的字体在哪里加载?

javascript - 恢复到旧版本的 Ionic 2 CLI

Angular 5 : Cannot match any routes

javascript - 如何修复 Angular Material Components 的构建错误?

javascript - Angular Material主题不改变颜色

angular - MatTableDataSource : cannot read property 'length' of undefined

javascript - 如何在 Angular 4 模块中延迟加载库?

javascript - 拉刷新奇怪的行为