I am attempting to access and read the information stored in my JSON file using my "GetJsonService".
app.component.ts:
data: any;
constructor(private jsonService: GetJsonService) {}
ngOnInit() {
this.getRecords();
console.log(this.data);
}
getRecords() {
this.jsonService.retrieveRecords().subscribe(data => {
this.data = data;
}, err => {
console.log(err);
});
}
get-json.service.ts
constructor(private http: Http) { }
data: any;
retrieveRecords() {
return this.http.get('assets/standorte.json').map(data => {
this.data = data.json();
return data.json();
}, err => {
if (err) {
return err.json();
}
});
}
I aim to assign the contents of data.json() to this.data for further use. However, when I output this.data, it shows as "undefined".
I am fairly new to Angular 2 and Typescript, so I would greatly appreciate any assistance.
Best regards!