Hi
I have below Html of one component. I want to display Data in a common Angular material table. How it can be done in Common table.
Code
Product Form
Product Name
This is required
Minimum length is 4 -->
Product Description
Product Image
Cancel
SaveThanks

Dharmeshwaran SRank #819 · 2.8K reputationPosted Jun 21, 2024, 10:26 AM EDT
To display the provided data in a common Angular Material table, you need to implement an Angular component that uses the Angular Material table component (
).Sample Typescript Code:
import { Component, Input, OnInit } from '@angular/core'; @Component({ selector: 'app-dynamic-mat-table', templateUrl: './dynamic-mat-table.component.html', styleUrls: ['./dynamic-mat-table.component.css'] }) export class DynamicMatTableComponent implements OnInit { @Input() lstData: any[] = []; @Input() columns: any[] = []; displayedColumns: string[] = []; ngOnInit(): void { this.displayedColumns = this.columns.map(col => col.columnDef); } }Html Code:
Use the Created Component in your Existing Component
Thanks!!