Without using httpClient
the alternative is to import the json, transcribed from the original link because it is quite explanatory:
In ES6 / ES2015, you can import a json file directly into the code. For example,
example.json
{
"name": "testing"
}
You can import it in ES6 / ES2015 in this way:
// ES6/ES2015
// app.js
import * as data from './example.json';
const word = data.name;
console.log(word); // output 'testing'
However, in Typescript, this code will give an error:
Can not find module 'example.json'
Solution: Use "Wildcard Module Name", add in the definitions file:
typings.d.ts
declare module "*.json" {
const value: any;
export default value;
}
Then the import works like this
// Typescript
// app.ts
import * as data from './example.json';
const word = (<any>data).name;
console.log(word); // output 'testing'
references:
link
link