Mpondomise Mpondomise - 11 months ago 59
AngularJS Question

angularjs firebase login scope value is not available after refresh

I have my

in the
and I try to access it from other views after the user has logged in, using:

however, when I refresh the page immediately after the user has successfully signed in, the
value reverts back into
and the parameter isn't available. How can I save this data persistently throughout the logged in session?
Can you please provide the answer with an example?

app.controller("MyregisterCtrl", ["$scope", "$stateParams", "Auth", "$state", "$location", "$modal", "DatabaseRef", "$rootScope",
function ($scope, $stateParams, Auth, $state, $location, $modal, DatabaseRef, $rootScope) {
$scope.user = {};
$scope.signIn = function () {
if (!$ && !$scope.user.password) {
toastr.error("Add email and password");
} else {
Auth.$signInWithEmailAndPassword($, $scope.user.password)
.then(function(firebaseUser) {

var userId = firebase.auth().currentUser.uid;
DatabaseRef.ref('/users/' + userId).once('value')
.then(function(snapshot) {
pseudonym = snapshot.val().pseudonym;
console.log("pseudonym: ", pseudonym);
$scope.pseudonym = pseudonym;

if (!firebaseUser.emailVerified) {
// firebaseUser.sendEmailVerification();'Your email is NOT verified.', 'Verify email!');
// $state.go('home');
.catch(function(error) {
toastr.error(error.message, error.reason, { timeOut: 10000 });
$scope.user = {};

Answer Source

You should use a Service to store the value and retrieve it whenever you need.

var myApp = angular.module('myApp',[]);
myApp.service('mySingleton', function() {
    var username= "test";
    return {
        username : username

function MyCtrl($scope, mySingleton) {
    $scope.username= mySingleton.username;

function MyCtrl2($scope, mySingleton) {
    $scope.username= mySingleton.username;