Having difficulty accessing the _embedded property within Json in Angular. Wondering if it's even possible. The Json response, created using Spring-Data-Jpa, is structured like this:
{
"_embedded": {
"reviews": [
{
"author": "Anonymous",
"content": "This movie sucks",
"upvotes": 0,
"downvotes": 0,
"_links": {
"self": {
"href": "http://localhost:8080/api/reviews/1"
},
"review": {
"href": "http://localhost:8080/api/reviews/1"
},
"film": {
"href": "http://localhost:8080/api/reviews/1/film"
}
}
}, ...
]
},
"_links": {
"self": {
"href": "http://localhost:8080/api/reviews{?page,size,sort}",
"templated": true
},
"profile": {
"href": "http://localhost:8080/api/profile/reviews"
}
},
"page": {
"size": 20,
"totalElements": 6,
"totalPages": 1,
"number": 0
}
} I am trying to extract and process reviews nested within the embedded field from my Client app. However, I am encountering challenges accessing the _embedded property. The snippet of my Angular Service is as follows:
getEmbedded(): Observable<any> {
return this.http.get(ServerConfig.serverAddress + '/api/reviews');
}
Here is the component that utilizes the service:
export class ReviewListComponent implements OnInit {
embeddedReviewResource: any;
constructor(private reviewService: ReviewService) { }
ngOnInit() {
this.reviewService.getEmbedded().subscribe(data => {
this.embeddedReviewResource = data;
});
}
I have attempted various methods to reference the _embedded property in my view:
*ngFor="let review of embeddedReviewResource.reviews
or
*ngFor="let review of embeddedReviewResource._embedded.reviews
or
*ngFor="let review of embeddedReviewResource.getEmbedded().reviews
or
*ngFor="let review of embeddedReviewResource._embeddedViews.reviews
Unfortunately, none of these approaches seem to work. How can I access the _embedded property within the Json File? You can find the complete source code on my GitHub.