{"flag":true,"single":true,"pageTitle":"angular import json file from assets","post":{"id":87,"user_id":"1","slug":"angular-import-json-file-from-assets-ay2s","title":"angular import json file from assets","body":"<p>You can&nbsp; import the JSON file directly in your TypeScript file using the import statement.<\/p>\r\n<p><strong>Directly:<\/strong><\/p>\r\n<p>1.Import it in any component.js file<\/p>\r\n<pre class=\"language-markup\"><code>import  jsonis from '..\/json\/json.json';<\/code><\/pre>\r\n<p>2. Acess your json inside component methods<\/p>\r\n<pre class=\"language-markup\"><code>export class HomeComponent {\r\n  constructor(){\r\n    console.log(data);\r\n  }\r\n}<\/code><\/pre>\r\n<p>3. Open your <strong>tsconfig.json file <\/strong>Add the <strong>resolveJsonModule <\/strong>and <strong>esModuleInterop <\/strong>options to the compilerOptions section:<\/p>\r\n<pre class=\"language-markup\"><code>{\r\n  \"compilerOptions\": {\r\n    \"resolveJsonModule\": true,\r\n    \"esModuleInterop\": true,\r\n    \/\/ ...\r\n  },\r\n  \/\/ ...\r\n}\r\n<\/code><\/pre>\r\n<p>&nbsp;<\/p>","category_id":"13","is_private":"0","created_at":"2023-03-31T01:44:21.000000Z","updated_at":"2023-03-31T01:44:21.000000Z","category":{"id":13,"user_id":"1","name":"Angular","slug":"angular-rfjp","parent_id":"12","created_at":"2023-03-24T03:25:15.000000Z","updated_at":"2023-03-24T03:25:15.000000Z"},"user":{"id":1,"name":"R GONDAL","email":"rizikmw@gmail.com","email_verified_at":null,"two_factor_confirmed_at":null,"current_team_id":"1","profile_photo_path":null,"created_at":"2023-03-12T10:49:33.000000Z","updated_at":"2025-01-10T12:59:00.000000Z","profile_photo_url":"https:\/\/ui-avatars.com\/api\/?name=R+G&color=7F9CF5&background=EBF4FF"}},"pageDesc":"You can&nbsp; import the JSON file directly in your TypeScript file using the import statement. Directly: 1.Import it in any component.js fi - angular import json file from assets (Updated: March 31, 2023) - Read more about angular import json file from assets at my programming site [SITE]","categories":[]}