Reading CSV File on Angular

Creating an Angular Project

For visual learner, you can watch the tutorial from youtube. link

In this brief article, I will be explaining how to read CSV files in the Angular Project. We will be using CSV file provided by CDC in the project. The link is

First of all, we will start our project. You can type the following code on your command panel or terminal to start the project.

After the project has been successfully created. We will be creating a service in Angular that will help us to interact with our CSV file. To create service type the following command

After the service is created, we will now create an Angular Component file. To create a component file type

After the component has been created. Go to app.component.html and remove all the HTML content from the page, then add the following line of code in the HTML page

<app-cases-report> is the selector name that you can find in you rcomponent.ts file. The name of the file can be different based on the name of the component that you wrote.

Run the command

In your http://localhost:4200/ ,you should see it running like below.

Working with CSV File on Angular

Now let’s go to file. We will be needing HttpClient module for the project to make HTTP get requests. In order to add HttpClient module, go to your app.module.ts and add

imports: [ HttpClientModule ]

Now In your covid.service.ts file, import HttpClient module

Make sure you initialize HttpClient from your constructor.

Here, we are basically using get method from Http to read our CSV file.

Now go to your cases-report.component.ts file and write the following code. Make sure you import CovidService in the file.

Now we have successfully sent our CSV file in an Array of covidData. To display the data on your localhost, go to you cases-report.component.html file and write the following code

<div *ngFor=”let covid of covidData”>

<p> {{ covid }}</p>


You can now check your local browser and it should load the data as shown in the screenshot below.

That’s all !! we have now successfully read a CSV file in Angular. In the next article, I will write about how to use this data for Visualization.

Software Engineer