I have an Angular Frontend with Spring-Boot Backend integration. For testing purposes i want to get database entries in the Console.log. It works that I get the specific entries, but the Output is only [object Object] instead of the real database-entry.
This are my service-methods (just a part), where I got a Get-Method for getting all my entries and jsut for a specific entry (which is marked with an ID):
getVorgaenge(): Observable<any> {
return this.http.get(this.getDataURL);
}
getVorgaengeID(id: number): Observable<any> {
return this.http.get(`${this.getDataURL}/${id}`);
}
My component.ts looks like this:
constructor(private http: HttpClient, private vorgangService : VorgangService) { }
vorgaenge: any;
ngOnInit() {
this.getAllVorgaenge();
}
getAllVorgaenge() {
this.vorgangService.getVorgaenge().subscribe(
data => {
this.vorgaenge = data;
console.log("Alle Einträge:" + this.vorgaenge);
data = Math.max.apply(0, this.vorgaenge.map(function(v) {return v.id}));
console.log("Höchster Eintrag: " + data);
this.vorgangService.getVorgaengeID(data).subscribe(newdata => {
this.vorgaenge = newdata;
})
console.log("Eintrag mit höchster ID: " + this.vorgangService.getVorgaengeID(data));
})
}
I want to get the last entry of the database (i've done this with the Math.max-function. It works fine, but the output in the console is only "Eintrag mit höchster ID: [object Object]"
I need the exact entry of the last entry (of which i get the ID with Math.max). It should be working, but the output needs to be converted to the real json-database-entry.