Introduction
Here, we will learn about how we can dynamically add/remove rows of the grid using Angular 7. We have performed the same functionality with AngularJS also, you can refer to it from here.
Prerequisite
- Basic knowledge of Angular 7
- Any Editor likes Visual Studio Code
- Angular CLI must be installed
- Node JS must be installed
Let's get started
Open the Visual Studio code and open a new Terminal.

Type the following command in it.
- ng new dynamic-grid

We will also install the Bootstrap and Toaster as we are going to use it further.
- npm install bootstrap
- npm install ngx-toastr --save


Open the project in Visual Studio Code by opening the folder.

Choose the folder and open it.

Now it's time to create the component for the project, so open the terminal and type the following command,
- ng g c grid-view --routing

First, we will add the reference for bootstrap and toaster in the angular.json file.

Type the following command to generate the model file for the class.
- ng g class grid.model

We're all done with installation and project setup. Now we will code the project.
Open the app.module.ts file present in the root folder and add the references there.
- import { BrowserModule } from '@angular/platform-browser';
- import { NgModule } from '@angular/core';
- import { ToastrModule } from 'ngx-toastr';
- import { AppRoutingModule } from './app-routing.module';
- import { AppComponent } from './app.component';
- import { GridViewComponent } from './grid-view/grid-view.component';
- import { FormsModule } from '@angular/forms';
- import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
- @NgModule({
- declarations: [
- AppComponent,
- GridViewComponent,
- ],
- imports: [
- BrowserModule,
- AppRoutingModule,
- FormsModule ,
- BrowserAnimationsModule,
- ToastrModule.forRoot()
- ],
- providers: [],
- bootstrap: [AppComponent]
- })
- export class AppModule { }
- <div class="container">
- <app-grid-view></app-grid-view>
- </div>
Open the index.html file and add the reference for font-awesome.
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>DynamicGrid</title>
- <base href="/">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="icon" type="image/x-icon" href="favicon.ico">
- <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
- </head>
- <body>
- <app-root></app-root>
- </body>
- </html>


Hamid KhanPosted Oct 14, 2020, 5:19 AM
Good explanation ...........Thanks
Neeraj SinghPosted Jun 12, 2020, 2:40 PM
Very nice :)
deepak karmaPosted Apr 27, 2020, 6:41 AM
My view is not updating automatically
Yogesh vijayanPosted Sep 5, 2019, 10:40 AM
Please help me out to fetch user table data and save it to database
Yogesh vijayanPosted Sep 5, 2019, 9:49 AM
CAN YOU TELL HOW TO SAVE THE TABLE DATA IN DATABASE. (i.e) how to get user inputs in angular 7