Angular Material Table Example| Angular Mat Table Example

By Hardik Savani May 2, 2024 Category : Angular


Today our leading topic is angular material table example. This article goes in detailed on angular material mat-table example. i explained simply step by step angular material mat table example. We will look at example of angular 11 mat table example.

@angular/material/table package provide to adding material table to your angular project. here we will see material table simple example with preview, you can easily use with angular 6, angular 7, angular 8, angular 9, angular 10, angular 11, angular 12, angular 13, angular 14, angular 15, angular 16 and angular 17 version.


Step 1: Create New App

You can easily create your angular app using bellow command:

ng new myNewApp

Step 2: Install npm Package

Now in this step, we need to just install angular/material in our angular application. so let's add as like bellow:

ng add @angular/material

Step 3: Import MatTableModule

we will import MatTableModule module as like bellow code:


import { NgModule } from '@angular/core';

import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { MatTableModule } from '@ngmodule/material-carousel';


declarations: [



imports: [





providers: [],

bootstrap: [AppComponent]


export class AppModule { }

Step 4: Update Ts File

here, we need to update ts file as like bellow:


import { Component } from '@angular/core';


selector: 'app-root',

templateUrl: './app.component.html',

styleUrls: ['./app.component.css']


export class AppComponent {

data = [

{id: 1, name: 'Rajesh', email: ''},

{id:2, name: 'Paresh', email: ''},

{id:3, name: 'Naresh', email: ''},

{id:4, name: 'Suresh', email: ''},

{id:5, name: 'Karan', email: ''},


displayedColumns = ['id', 'name', 'email'];

constructor() {}


Step 5: Update HTML File

here, we need to update html file as like bellow code:


<h1>Angular Material Table Example -</h1>

<table mat-table [dataSource]="data" class="mat-elevation-z8">

<!--- Note that these columns can be defined in any order.

The actual rendered columns are set as a property on the row definition" -->

<!-- ID Column -->

<ng-container matColumnDef="id">

<th mat-header-cell *matHeaderCellDef> ID </th>

<td mat-cell *matCellDef="let element"> {{}} </td>


<!-- Name Column -->

<ng-container matColumnDef="name">

<th mat-header-cell *matHeaderCellDef> Name </th>

<td mat-cell *matCellDef="let element"> {{}} </td>


<!-- Email Column -->

<ng-container matColumnDef="email">

<th mat-header-cell *matHeaderCellDef> Email </th>

<td mat-cell *matCellDef="let element"> {{}} </td>


<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>

<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>


Now you can run by bellow command:

ng serve

now you can check it.

I hope it can help you...