How to keep $stateparams parameters after i refresh the browser

て烟熏妆下的殇ゞ 提交于 2019-12-24 00:25:58

问题


I have this list of users .. When a user clicks in one of those user in the list.. it will redirect me to my profileState with the associated UID of the user. I use state parameters to pass the UID from the userListState to the profileState.. When i type

console.log($stateParams);

it displays the UID which i passed from userListState .. but once i refresh the page.. the UID will become null.. So i would like to know how you guys make that specific data remain there after page reload.


回答1:


How do you have configured your states? becuase you should do something like

.state('app.profile', {
    url: '/profile/:uid',
    views: {
        '@app': {
            templateUrl: 'app/profile/index.html',
            controller: 'ProfileController as profileCtrl'
        }
    },
    params: {
        uid: null
    }
})

this way when you go to your state you'll end up with localhost/profile/234

you will refresh and uid will be there.




回答2:


There are 2 common ways to store your uid:

  1. Assign variables to $rootScope, that way its visible to all the controllers

  2. localStorageService , this will hold the values even after user refreshes the page.



来源:https://stackoverflow.com/questions/40788230/how-to-keep-stateparams-parameters-after-i-refresh-the-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!