首页 文章

Angular Material中的动态值 - 排序 Headers

提问于
浏览
1

如何在物料排序中使用"id"来注入动态值?当我尝试使用插值 mat-sort-header 导致错误时 - 't bind to ' mat-sort-header ' since it isn' t 'th'的已知属性

该表是动态构建的 .

<table matSort (matSortChange)="sortData($event)">
<tr>
<th mat-sort-header="{{mapped.id}}" id="{{mapped.id}}">{{mapped.header}}</th>   
</tr>...
</table>

我正在使用 import from '@angular/material';

它取自https://material.angular.io/components/sort/overview

非常感谢

2 回答

  • 0

    试试这个:

    <table matSort (matSortChange)="sortData($event)">
        <tr>
            <th mat-sort-header id="{{mapped.id}}">{{mapped.header}}</th>   
        </tr>...
    </table>
    
  • 0

    您可能忘记添加MatSortModule .

    每当你看到类似的东西:

    无法绑定到[material-directive],因为它不是[element]的已知属性 .

    这表示您没有添加模块 .

    另外一种更有角度的写作方式是:

    <table matSort (matSortChange)="sortData($event)">
      <tr>
        <th [mat-sort-header]="mapped.id" [id]="mapped.id">{{mapped.header}}</th>   
     </tr>
    </table>
    

相关问题