I have an angular/ionic application, in which I make a server request.
After I get the data, my model(img src) should update its default value(assets/imgs/anyfile.jpg) to my new value(server/new/image/path)
But the screen is created after the request, or even before I don’t know…
The request is being made on ngAfterViewInit.
Where should call my updateImageFunction() so my images can be updated with the new values..?
Any help will do guys! Thx
I cannot provide the code, because I’m using the PureMVC Framework within Angular and Ionic. I can’t get a clean piece of code without its Notifications and directives. So I’m gonna detail a little bit.
The app is loaded with images A and B, whose paths comes from static attributes on a Service.ts file (default paths on assets folder);
Is made a request(ngAfterViewInit) where I get new paths and the Service.ts attributes are updated;
Because the screen is already loaded, the images already got its paths from the Service(default still) and the update comes after all this. The images A and B aren’t updated
I think its lifecycle problem, but don’t know how to workaround it…
Server requests in angular if you are using httpClient, are cold observables. This means that the subscription automatically dies once the http request is complete.
In order for you to always have the most up to date data and to refresh, what you need to do is on an event that causes change, make another http call to reload the data.
I can’t really give you a concrete example since you didn’t give any code but I hope this helps.
Answered By – Mike Tung