Please stop abusing any
and declare return types for all functions. Your code will be easier to understand if you give everything proper types, and that will also help the build tools and your IDE guide you through this.
imagesUrlFunction
doesn’t actually return anything, yet you are trying to assign that nothing to urlMedia
. A good rule of thumb is that functions should either modify state (object properties) or return something, but not both. You can write this either way, but should choose one.
That decision is pretty much mooted by the fact that interaction with the backend should be done in a service provider, not in the page. The page wants a list of strings, so that’s what I would give it:
interface TourImageSet {
guid: string;
}
interface TourResponse {
// bunch of stuff
tour_images: TourImageSet[];
}
export class TourProvider {
tourImages(): Observable<string[]> {
return this._html.get<TourResponse>(api).pipe(
map(rsp => rsp.tour_images),
map(isets => isets.map(iset => iset.guid)));
}
}
export class ToursPage {
whenever() {
this._tours.tourImages().subscribe(urls => {
// urls should be exactly the array of strings we wanted in the first place
});
}
}