angular import json file from assets
You can import the JSON file directly in your TypeScript file using the import statement.
Directly:
1.Import it in any component.js file
import jsonis from '../json/json.json';
2. Acess your json inside component methods
export class HomeComponent {
constructor(){
console.log(data);
}
}
3. Open your tsconfig.json file Add the resolveJsonModule and esModuleInterop options to the compilerOptions section:
{
"compilerOptions": {
"resolveJsonModule": true,
"esModuleInterop": true,
// ...
},
// ...
}