My task involves retrieving data from the Flickr API, specifically the "photo" array from a given URL. While I have successfully achieved this by fetching the data in the app.component and manipulating it accordingly, I realize that this approach may not be ideal.
Here are my attempts:
photo.ts:
export class Photo {
title: string;
farm: number;
secret: string;
server: string;
owner: string;
id: string;
};
app.component.ts:
export class AppComponent implements OnInit {
photos: Photo[];
constructor(private http: HttpService) {}
ngOnInit() {
this.getData();
}
getData() {
this.http.getData().subscribe(data => {
this.photos = data;
});
}
}
And now onto my main obstacle, http.service.ts:
export class HttpService {
constructor(private http: HttpClient) { }
getData(): Observable<Photo[]> {
return this.http.get('https://api.flickr.com/path')
.map(res => res.photos.photo);
}
}
Although I believe everything is set up correctly, I encounter an error:
ERROR in src/app/http.service.ts(18,23): error TS2339: Property 'photos' does not exist on type 'Object'.