Reputation: 128
In my application,I show user-name at side-menu header with ng-bind. This user-name is comes from local-storage. But when i edit user-profile and also user-name,and override it to local-storage. After that the new username is not showing to the sidemenu-header. But when i refresh the page from browser or reopen the application,it shows new one efficiently. So what should i do for refresh the content of side-menu (user-name) ?? It take slot of my time.... answer will be appreciated... Thanks :)
hi,anied Thanks for replying. I share my code below....
I set the first_name and last name to the local-storage that comes from service response. and login-page URL is==> http://localhost:8100/#/login
localStorage.setItem("firstname",JSON.stringify($scope.dataa.first_name)); localStorage.setItem("lastname",JSON.stringify($scope.dataa.last_name));
and i get it to my ionic menu controller.... var firstname={}; var lastname={}; $scope.firstname=JSON.parse(localStorage.getItem('firstname')); $scope.lastname=JSON.parse(localStorage.getItem('lastname'));
and url of this is==>http://localhost:8100/#/menu/dashboard1 a root page 'menu'.
When i edit page, i set this content again to local-storage.But it not showing to menu header.But when i refresh the page it shows efficiently. I think this is the root url problem==> /menu/ is never refresh in this app.
I edit this content with this url==>/localhost:8100/#/menu/editprofile so,it not refresh root url page. But when i edit profile with this url==>/localhost:8100/#/editprofile it,refresh content automatically.... and not for above url. Hope you understand. answer will be appriciated. thanks
Upvotes: 0
Views: 86
Reputation: 13623
Without seeing any of your code, my hunch is to try doing a $scope apply inside of a timeout:
$timeout(function () {
$scope.$apply();
}
Do the above after you have changed the bound data and see if that forces a refresh of the UI.
(Incidentally, if you are attempting to bind the data directly to localStorage, I doubt that that will work -- you probably either need to hold the data in memory, or bind to a function that fetches it from localStorage, depending on your needs.)
Upvotes: 0