Skip to content
Advertisement

Angular 5 Service to read local .json file

I am using Angular 5 and I’ve created a service using the angular-cli

What I want to do is to create a service that reads a local json file for Angular 5.

This is what I have … I’m a bit stuck…

JavaScript

How can I get this finished?

Advertisement

Answer

First You have to inject HttpClient and Not HttpClientModule, second thing you have to remove .map((res:any) => res.json()) you won’t need it any more because the new HttpClient will give you the body of the response by default , finally make sure that you import HttpClientModule in your AppModule :

JavaScript

to add this to your Component:

JavaScript
Advertisement