Answers for "show json data in html angular"

0

get data from json file angular

/*--IN THE TS OF THE COMPONENT--*/
//In imports section
import variableName from '../../assets/fileName.json';

//In the class part of the same file
export class AppComponent {
  //This variable will have all the values
  public nameList:{field1:type, field2:type}[] = variableName;
}

/*--IN A NEW TS FILE--*/
//Create another js file in the app folder with
declare module "*.json" {
	const value: any;
	export default value;
}
Posted by: Guest on March-02-2021
0

show json data in html angular

<!--JSON data in the ts component:-->
data = [
  {
    title: 'Title 1',
    content: 'Lorem ipsum'
  },
  {
    title: 'Title 2',
    content: 'Lorem ipsum2'
  }
]

<!--In the HTML component:-->
<div *ngFor="let dat of data">
  <h1>{{dat.title}}</h1>
  <p>{{dat.content}}</p>
</div>
Posted by: Guest on October-26-2021

Browse Popular Code Answers by Language