json

Angular – import .json

Table of Contents

Intro

How to add .json file in to your Typesctipt for Angular

Sources

Snippet

				
					// tsconfig.json
"compilerOptions": {
    ...
    "resolveJsonModule": true
  }
				
			
				
					// your.ts
import * as data from './example.json';
				
			

Angular – local .json Server

Table of Contents

Sources

Starter-Code

				
					npm install -g json-server
				
			
				
					// server.json
{
  "users": [{
      "id": 1,
      "name": "Byron Carlson"
    }, {
      "id": 2,
      "name": "Sebastian Jacobs"
    }, {
      "id": 3,
      "name": "Cassandra Holland"
    }, {
      "id": 4,
      "name": "Henry Hanson"
    },
    {
      "id": 5,
      "name": "Chelsey Dietrich"
    }, {
      "id": 6,
      "name": "Kurtis Weissnat"
    }
  ]
}
				
			
				
					json-server --watch server.json
				
			
				
					Resources
http://localhost:3000/users

Home
http://localhost:3000