jeudi 5 octobre 2017

How to get .json files included in a build in Angular 4 project?

In a directory root/src/app/lsg/demo-parent, I am including the following files:

demo-parent.module.ts
demo-parent.component.ts
demo-parent.component.spec.ts
demo-parent.component.html
demo-parent.component.scss
demo-parent.routing.ts
en.json
fr.json

I need access to the content that is in en.json and fr.json when the application is running. I am using a third party library, ngx-translate, which is used for i18n/internationalization. ngx-translate wants you to put all your [lang].json files in a main root/src/assets/i18n directory, but for our project we need the translation files to live in the same directories as the components.

If I do this in my .angular-cli.json file:

  "assets": [
    "assets",
    "favicon.ico",
    "app"
  ],

(i.e. adding "app" to the assets array) ...then I can get to the .json files that live in each component directory. But we don't want to expose app this way.

When I run ng serve and go to the devTools and look at "Sources", I can see the following lives in the DemoParentModule directory:

DemoParentComponent.html
DemoParentComponent.ngfactory.js
DemoParentComponent.ngfactory.js? [sm]
DemoParentComponent_Host.html
DemoParentComponent_Host.ngfactory.js
DemoParentComponent_Host.ngfactory.js? [sm]
module.ngfactory.js
module.ngfactory.js? [sm]

Everything I need is there...except the .json files.

How can I get the .json files to be included in these directories when I run ng serve?

Aucun commentaire:

Enregistrer un commentaire