How can I serve JSON in Angular?

I have an Angular 4 application created using Webpack and I'm trying to use a JSON file. Two questions:

  • In the simplest case, the JSON file is static. I cannot figure out how to configure webpack to include a myfile.jsonway to include images. However, if I look at the URL of any image on the page, it looks like assets/angular.9db278d630f5fabd8e7ba16c2e329a3a.png. I would rather have a simpler URL for my JSON.
  • In a less simple case, I create the file programmatically. Building a JSON string is obviously not a problem, but displaying it. I looked at examples of how to display PDF files, but they require a plugin, and most of them are simply called window.openin another window. Since Angular components are displayed in a tag on a web page, I am having problems with a page break.

Is it possible? I understand, I asked two questions, but I will be pleased with the answer to one of them; not for both :)

+4
source share
1 answer

webpack 1, json-loader; JSON webpack 2 (. README json-loader).

JSON import myFile from ./myfile.json.

, - , . , JSON angular?

+3

Source: https://habr.com/ru/post/1681235/


All Articles