Last active
October 13, 2022 05:54
-
-
Save lorenzojkrl/62463c0ff1b0543c92782de437d17c39 to your computer and use it in GitHub Desktop.
Use Import 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 * as jsonData from '../assets/data.json'; | |
@Component({ | |
selector: 'my-app', | |
template: ` | |
<h1>{{ title }}</h1> | |
`, | |
}) | |
export class AppComponent implements OnInit { | |
title = 'Read A JSON File From Assets'; | |
data: any = jsonData; | |
ngOnInit() { | |
console.log('Data', this.data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment