How to update the side menu profile pic after login and logout the app

hi,I got an issue for side menu in ionic.I have profile pic upload module in side menu.where i use to upload pic and when it is uploaded succesfully in server. i want to show in my side menu.it will not update soon as i navigate to side menu after uploading my pic while i when restart the app then pic is visible to me in side menu.i want pic visble to me in side menu after uploading .i use localstorage for image path .as i have apply ionviewdidenter in app.component.ts,so that it visble to me after it loads.can anyone let me know how to use ionviewdidenter in app.component.ts because it is not working there,as i have applied this function in other pages.or any other suggestion in app.component.ts to load it again ??? image

If I understood correctly your issue, I think you have several possibilities :

  • I guess you store your new image path in localstorage when the picture is successfully uploaded ? In that case, you could fire an event when your image is uploaded, and update the path. (not tested)

  • The solution I already used : store the path in a global variable (in localstorage too), and set the path in the img src with this variable. When the server finishes uploading the new picture, just update this var with the new path, and the src should update too. Store the path in your localstorage at the same time, so when you open the app again you set that value from the localstorage to the global variable.

event is working but i want to reload the sidemenu after login is that possible becouse the app.html file is loaded first but the data of user come after login in local storage

Well, I don’t think reloading the sidemenu is a good idea. You should reload all the user data when the event is triggered, the same way you did with image path.

I never had to use it, but may be creating a User model, with attributes you set in the view (like {{user.name}}, …) is the best solution. When the user is logged in, you set the values in localstorage and in the user object, then trigger the login event, that updates the user’s attributes from the user object. Then the view is automatically updated (may be with Injectable class, I don’t know how to update a model, but you should find it easily). On the next start, you set the value on the User object from the localstorage.

And you should think about using Ionic Storage instead of localstorage. Because localstorage is not always reliable.

its not working i use events but still that side menu image not change

I had the same problem for months, just found the solution now, the solution is using Events

1 Like

yes its working with events