This is the code snippest in my service.ts(this.http is a HttpClient obj)
importAllImages (): Observable<Image[]> {
return this.http.get<Image[]>('http://localhost:8080/fileservice/allimages');
}
And this is the code snippest that calls the service shown above(filemanager is an obj of the service above and images is an array of image obj):
this.fileManager.importAllImages().subscribe(imagesp => this.images = imagesp);
console.log(this.images.length);
And my html:
<div *ngFor="let image of images">
<p>{{image?.imageName}}</p>
Then i open http://localhost:4200 but i can't get any image names in it.
PS:I have successfully start my backend SpringBoot Application and i can see my JSON data when i open http://localhost:8080 like this: JSON Data image Can someone help me with this?
You need to return json, so you need to deserialize the response object to json:
importAllImages(): Observable<Image[]> {
return this.http.get('http://localhost:8080/fileservice/allimages')
.map((response) => {
return response.json();
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.