How to display static JSON data in table in Angular ?
Last Updated :
24 Apr, 2025
In this article, we will see How to display static JSON data in the table in Angular. We will be displaying static data objects in Angular Table. We need to iterate over the object keys and values using key values and then handle them in the table. We will be using the bootstrap table and Angular PrimeNG Table template
Steps for Installing & Configuring the Angular Application
Step 1: Create an Angular application using the following command.
ng new appname
Step 2: After creating your project folder i.e. appname, move to it using the following command.
cd appname
Project Structure
It will look like the following:
Example 1: In this example, we will use a normal bootstrap table to display the static JSON data. We will be iterating over the JSON object using keyvalue.
HTML
<!-- app.component.html -->
<head>
<link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
</head>
<h2 style="color: green">GeeksforGeeks</h2>
<h2>
How to display static JSON data in table in Angular
</h2>
<table class="table table-striped" style="width:50%">
<thead>
<tr>
<th>
Sr No.
</th>
<th>
Course
</th>
<th>
Cost
</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of gfg|keyvalue">
<td>{{item.key}}</td>
{{set(item.value)}}
<td *ngFor="let element of gfg2|keyvalue">
{{element.value}}
</td>
</tr>
</tbody>
</table>
JavaScript
// app.component.ts
import { Component, OnInit } from '@angular/core';
import { KeyValue } from '@angular/common';
import { Pipe, PipeTransform } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: "./app.component.html",
styleUrls: ['./app.component.css']
})
export class AppComponent {
gfg: any =
{
"3":
{
"course": "Java",
"cost": "1000"
},
"4":
{
"course": "React",
"cost": "1500"
},
"2":
{
"course": "Angular",
"cost": "1700"
}
,
"1":
{
"course": "CSS",
"cost": "800"
}
}
gfg2: any
set(obj: any) {
this.gfg2 = obj
}
}
JavaScript
// app.module.ts
import { NgModule }
from '@angular/core';
import { BrowserModule }
from '@angular/platform-browser';
import { HttpClientModule }
from '@angular/common/http';
import { AppComponent }
from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpClientModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }