Angular4: how do access local json?

前端 未结 7 2199
傲寒
傲寒 2020-12-06 05:00

In Angular2 you could have a folder /data/ and a json file there and you could access it at localhost:4200/data/something.json.

This is no longer possible in Angular

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 05:52

    I was facing the same issue, where my Observable Angular service was located at inside 'src/app/' folder and it was trying to load a local JSON file. I tried to put the JSON file inside the same app folder, inside a new 'api' folder, used various kinds of relatives/absolute routes, but it didn't help and I got 404 error. The moment I put it inside 'assets' folder, it worked. I guess there is more to it?

    Maybe this link helps:

    COMPONENT-RELATIVE PATHS IN ANGULAR

提交回复
热议问题