Nevin
Nevin

Reputation: 375

How to keep $stateparams parameters after i refresh the browser

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.

Upvotes: 2

Views: 3033

Answers (2)

Rai Vu
Rai Vu

Reputation: 1625

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.

Upvotes: 0

Gerardo Rosciano
Gerardo Rosciano

Reputation: 901

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.

Upvotes: 4

Related Questions