For the purpose of learning, I am developing a small Ionic app where I want to load data from a JSON file and map it to an interface that defines the data structure. However, I am facing challenges in achieving this:
import { Component } from "@angular/core";
import { HttpClient} from "@angular/common/http";
export interface PhonebookEntry {
name: string,
telephone: string,
description: string
}
@Component({
selector: 'page-phonebook',
templateUrl: 'phonebook.html'
})
export class PhonebookPage {
entries: Array<PhonebookEntry>;
constructor(public http: HttpClient) {
this.load_entries('assets/json/phonebook.json');
};
load_entries(filePath: string) {
return this.http.get(filePath)
.subscribe(
data => this.entries = data
);
};
}
It seems like only the line data => this.entries = data
is causing an issue (my IDE is indicating that), but I am unsure of the correct way to handle this. I have searched for documentation on this topic without success. If anyone knows of any resources that can help, I would greatly appreciate it.