Reputation: 9746
I want so set a $rootScope
variable stateSelection
value default as false
.
So when my applciation runs the value of the $rootScope.stateSelection
will be false
. I want to know how to set it at the time of initialization of app.
Right now i am setting it in my Auth
Service in login
function.
When User logs in & selects a state i call a method in a controller named clickSelection()
& in this function i change the $rootScope.stateSelection = true;
.
I get a problem when i refresh the page, the value of $rootScope.stateSelection
becomes false
.
Thanks
Upvotes: 0
Views: 1078
Reputation: 449
$rootScope.stateSelection will always be false on refresh unless you're persisting the value somewhere.
If you are persisting the data somewhere, you can use the resolve property (read more about resolves here ) to return a function that will set the value before loading the page:
$stateProvider
.state('home', {
url: '/home',
templateUrl : 'views/home.html',
controller : 'HomeController',
resolve : {
authenticate : function auth(authService){
// Function to get the stateSelection value
return authService.getStateSelection()
}
}
}
Upvotes: 1