I am trying to get data from a json file located in assets folder. But instead getting error.
heroes.service.ts
getPeopleData(): Observable<people[]>{
return this.http.get<people[]>('assets/data/someData.json');
}
people.interface.ts
export interface people{
id: number,
name: string,
age: number
}
someData.json:
[
{"id":1, "name": "Jack", "age": 21},
{"id":2, "name": "Rina", "age": 29},
{"id":3, "name": "Jonathan", "age": 42}
]
about.component.ts
peopleData:any;
ngOnInit() {
this.getPeople();
}
getPeople(): void {
this.heroesService.getPeopleData()
.subscribe(data => this.peopleData = data)
}
Error:
Can someone help me out, where is the problem? There are no errors in console instead.