Created
October 13, 2022 06:59
-
-
Save lorenzojkrl/34d4b6f71eb6eb22a6fce6ff7facdfc6 to your computer and use it in GitHub Desktop.
Use HttpClient To Read A JSON File From Assets In Angular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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