简体   繁体   中英

Angular 2 access JSON file

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM