Hi,
i m newbie developing an simple app that get data from a Wordpress template that has custom fields.
I can get all data from my WP backoffice including the costum fields data, except a object that inside my object data, and retrieving the data from that function and displaying it in my page.
The app is a simple tour app, where i a couple of fields for text and another field for images.
When i look to the object that i get from my call i get :
Sort of by definition, one of these has to fail, so you must settle on only one (probably the second). Also, write it like this:
<img [src]="toursM">
HTML5 doesnât need the â/â, and this syntax will work even with sanitized URLs, whereas src="{{foo}}" will fail subtly.
Finally, instead of assigning to tourImagesUrl each time though the loop, I think you want to initialize it to [] and then call push inside that loop instead. That way it will be a proper array that ngFor can work with.
Thanks for the reply.
I corrected the html has you advised.
I ve tried what you wrote but the problem still persists.
When you say inicialize the tourImagesUrl you say in the begining making like
tourImagesUrl:any=;
what i understand, the data provided by the loop should go to an object, my tourImagesUrl object.
that should be something like this
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
});
}
}
I have a tour provider that i use to get the data with all the tours.
I thought in creating a function in the provider to get the images urls but i only get the images urls when a tour is pushed. thats why i use the imagesUrlFunction their.
When i try to pull the function using provider it gives me an error for the length of my image object.
I canât make head or tail of that. Everything involving getting data belongs in the provider, not the page. That includes getting the URLs, and I would aim to write a function that has the signature above, returning Observable<string[]>. What parameters it needs and what it has to do to interact with the backend is up to you.
Thanks rapropos for your time,
i see that i have to learn a little more about data binding to get over this point.
I thought that a simple loop in my page would be enougth since i already have a provider to get the data i have right now in my app, and i can get the urls i need from that provider using the loop i wrote above .
But i quite understand what you are saying, to use a provider to get the any outside data i need into my app.
i tried the code above and couldnt figure out the problem with it or with me , my map in the pipe isnt âworkingâ.