Skip to content

Instantly share code, notes, and snippets.

@lorenzojkrl
Created October 13, 2022 06:59
Show Gist options
  • Save lorenzojkrl/34d4b6f71eb6eb22a6fce6ff7facdfc6 to your computer and use it in GitHub Desktop.
Save lorenzojkrl/34d4b6f71eb6eb22a6fce6ff7facdfc6 to your computer and use it in GitHub Desktop.
Use HttpClient To Read A JSON File From Assets In Angular
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'my-app',
template: `
<h1>{{ title }}</h1>
`,
})
export class AppComponent implements OnInit {
title = 'Read A JSON File From Assets';
private URL = '../assets/data.json';
constructor(private httpClient: HttpClient) {}
ngOnInit() {
this.httpClient.get(this.URL).subscribe(console.log);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment