I have a JSON file named reportConfig
that I need to access using Angular and TypeScript.
Below is the content of my JSON file:
{
"accessToken": "12345",
"style": "color",
"projection": "globe",
"zoomLevel": 5
"markerScale": 1.1
}
In addition, I've created a new class called ConfigModel
:
export class MapReportConfigModel {
accesToken: string;
style: string;
projection: number;
zoomLevel: number;
markerScale: number;
constructor(private httpClient: HttpClient) {}
// Method to read JSON data
getMapConfig(): Observable<ReportConfigModel > {
let configData = `assets/reportConfig.json`;
return this.httpClient.get<ReportConfigModel>(configData );
}
}
Now, I have a child component named ReportContainer
. My question is how can I call the getMapConfig()
method from the child component?
export class ReportContainerComponent implements OnInit {
constructor(
private httpClient: HttpClient,
private mapReportConfigModel: MapReportConfigModel
) {}
ngOnInit(): void {}
// Method to load initial map
loadMap(): void {
}
private getMapConfigData(): void {
this.httpClient.get(this.mapReportConfigModel);
}
}
I have attempted to implement this but am not sure if it's correct. Any help on resolving this issue would be greatly appreciated. I want to call this method from the child component to fetch JSON data.