Hi
How to use Angular Material Table as common component. I don't want to replicate in all components.
Thanks
Hi
How to use Angular Material Table as common component. I don't want to replicate in all components.
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jayraj ChhayaRank #304 · 8.2K reputationPosted Jun 19, 2024, 8:03 AM EDT
To use Angular Material Table as a common component, you can create a custom Angular component that encapsulates the table functionality. This approach ensures reusability and consistency throughout your application. Here's a basic example of how you can achieve this:
shared-table.component.htmlfile:shared-table.component.tsfile:import { Component, Input } from '@angular/core'; @Component({ selector: 'app-shared-table', templateUrl: './shared-table.component.html', styleUrls: ['./shared-table.component.css'] }) export class SharedTableComponent { @Input() data: any[]; displayedColumns: string[] = ['column1', 'column2', 'column3']; // Define your columns here }app-shared-tableselector in any component where you want to display the shared table: