How to keep $stateparams parameters after i refres

2019-07-27 04:22发布

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.

2条回答
不美不萌又怎样
2楼-- · 2019-07-27 04:54

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.

查看更多
看我几分像从前
3楼-- · 2019-07-27 05:05

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.

查看更多
登录 后发表回答