1

Is it possible to Load external json file in angular-cli using json loader with out editing default webpack-config.json file ?

3
  • yeah it is possible without editing webpack.config.js. Commented Sep 8, 2017 at 7:13
  • do you have a sample .I tried adding in the assets Commented Sep 8, 2017 at 7:51
  • ReferenceError: require is not defined Commented Sep 8, 2017 at 8:00

1 Answer 1

1

Of course, you can load JSONs, that's why you have json-loader. In the service that loads the json write this line:

import * as someName from './somePath/someFile.json;

This line may throw an error: [ts] cannot find module './somePath/someFile.json'.

That not a real error (if the path and file name are correct), but only a typescript-type error that easily can be fixed by adding this line to your typings.d.ts file (if you don't have this file you can create it under the src folder in your solution):

/* allow import .json files */
declare module "*.json"
{
  const value: any;
  export default value;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.