Hi
How the below code works
{{element[col]}}
{{col}}
{{element[col]}}
Thanks
Hi
How the below code works
{{col}}
{{element[col]}}
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mayooran NavamanyPosted Jul 10, 2024, 5:44 AM
Detailed Explanation
{{element[col]}} :*matCellDef="let element": This directive indicates thatelementwill be a row data object. It is a template definition for the table cell.{{element[col]}}: This displays the value of thecolproperty of theelementobject.:: This defines a column in the table. Thecolattribute is used to specify the name of the column.*ngFor="let col of displayedColumns": This directive creates a column for each item in thedisplayedColumnsarray.displayedColumnsis an array that contains the names of the columns to be displayed. {{col}} :*matHeaderCellDef: This directive is used to define the content of the header cell.{{col}}: This displays the column name in the header.Combining everything together:
with*ngForcreates a set of columns based ondisplayedColumns.element) for the given column.Here’s how you might use the provided code snippet within a complete
setup:Explanation:
: Defines the table and binds the data source to it.: Defines the header row for the table.: Defines the rows for the table.Data Source and Columns
In your component, you should define the
displayedColumnsanddataSource: