I am struggling to access a local JSON file in my component file via JavaScript. In Angular 1, I would just make a service and inject it into my controller, but am lost with Angular 2.
Asked
Active
Viewed 179 times
0
-
I don't understand what the problem is. You can make a `http.get(...)` request to the server to get the file. – Günter Zöchbauer Sep 16 '16 at 15:33
-
Requirement is the file is local, not on the server. I'm unsure of how to get the data into the component to use it. – user1876246 Sep 16 '16 at 15:34
-
Something like http://www.html5rocks.com/de/tutorials/file/dndfiles/ or http://stackoverflow.com/questions/371875/local-file-access-with-javascript? – Günter Zöchbauer Sep 16 '16 at 15:35
1 Answers
0
If you want to get data from local JSON file. First You need to get json data into varible using HttpClient
Angular 2 HttpClient Official Docs
then JSON data available to print Data
if your name data in jsonDATA variable then
<ul>
<li *ngFor="let newData of jsonData">
{{newData.name}}
</li>
</ul>
If you get any error after this, then please ask with your sample error code
Thanks

Shubham Kandiyal
- 340
- 2
- 13