2

How can I inject dynamic values as I did with "id" in material sort? When I try using interpolation mat-sort-header results in an error - Can't bind to 'mat-sort-header' since it isn't a known property of 'th'

The table gets built out dynamically.

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

I'm using import { Sort } from '@angular/material';

And it's taken from https://material.angular.io/components/sort/overview

thanks very much

2
  • What is your requirement? Dynamic values for headers? Commented Feb 1, 2018 at 4:53
  • No, the doc for sort uses hard coded values in the table. I have a dynamic table that loops through the prop name and (after reformatting) applies that header and subsequent value(s) to the column. However when I use interpolation for that mat-sort-header. it breaks Commented Feb 1, 2018 at 17:41

2 Answers 2

2

You might have forgotten to add the MatSortModule.

Whenever you see something like:

Can't bind to [material-directive] since it isn't a known property of [element].

It is a sign that you didn't add the module.

Also a more angular-y way of writing it is:

<table matSort (matSortChange)="sortData($event)">
  <tr>
    <th [mat-sort-header]="mapped.id" [id]="mapped.id">{{mapped.header}}</th>   
 </tr>
</table>
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.