"AngularJS makes it easy for the logged-in user's information to be accessible and available across

I need to ensure that user information is accessible across all views after logging in. How can I adjust the code to be able to retrieve the pseudonym from another view? Could you provide an example as well?

Below is my login controller:

app.controller("MyregisterCtrl", ["$scope", "$stateParams", "Auth", "$state", "$location", "$modal", "DatabaseRef",
    function ($scope, $stateParams, Auth, $state, $location, $modal, DatabaseRef) {
        $scope.user = {};

        $scope.signIn = function () {
            if (!$scope.user.email && !$scope.user.password) {
                toastr.error("Add email and password");
            } else {
                Auth.$signInWithEmailAndPassword($scope.user.email, $scope.user.password)
                    .then(function(firebaseUser) {
                        //=====user info=================
                        var userId = firebase.auth().currentUser.uid;
                        DatabaseRef.ref('/users/' + userId).once('value')
                            .then(function(snapshot) {
                                pseudonym = snapshot.val().pseudonym;
                                console.log("pseudonym: ", pseudonym);
                                return pseudonym;

                            });
                        //======================
                        $state.go('app.dashboard');

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

The

console.log("pseudonym: ", pseudonym);
statement provides the desired data, but I am unable to access it from other views by simply typing {{pseudonym}} for instance.

Answer №1

To display on the view, assign a value to a $scope variable:

let pseudonym = snapshot.val().pseudonym;
$scope.pseudonym = pseudonym;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Updating IP addresses in MongoDB

I am dealing with a nested schema in my mongoDB collection. Here's an example of how it looks: { "_id":"61d99bf5544f4822bd963bda0a9c213b", "execution": { "test_split":0, "artifacts&quo ...

Problem with AngularJS promise causing incorrect setting of 'this'

I am trying to populate a select list with data from a JSON file. Controller this.languages = []; var getData = $lcidFactory.obtainLCIDS(); getData.then( function(result){ this.languages = result.data; console.log(result.data); }, ...

Troubleshooting Email Communication Errors: A Persistent Challenge

I am new to nodemailer and trying to work on a simple application. However, I keep encountering errors within the nodemailer module when running my app. Here is my app.js code: const nodemailer = require('nodemailer'); const transporter = node ...

Prevent the occurrence of the dreaded 'undefined property' error when attempting to validate a grandchild property

I need to set the state of a React component to the location.state passed with React Router. If it doesn't exist, I want to set it to 0. However, in some cases, the parent (location.state) of the property I am checking for (currentItem) doesn't ...

Having trouble setting State in React with Typescript?

I have encountered an issue with merging strings in an array. Despite successfully joining two strings and logging the result using console.log('Dates: ' + mergedActions), the merged string doesn't seem to be set in this.state.MergedAllActio ...

How to bind parent object scope to MySQL query's anonymous callback in Node.js

As a newcomer to node.js, I am still working on understanding the concept of scoping anonymous functions. I have created an object with multiple methods and within one of my methods, I retrieve a MySQL connection from a pool and then execute a query on tha ...

Exploring the Synergy Between Play 2.3.x, Webjars, and Requirejs: Unveiling

Queries: Is there a way to streamline the process of setting paths and shims in requirejs for webjars and their dependencies without manual intervention? (Especially for webjars that include a requirejs.config() call?) Does anyone have a straightforward e ...

Is there a way to adjust the scrolling speed of a background image to be slower than the rest of

I'm searching for an example similar to this: Are there any efficient javascript solutions available? I've had difficulty implementing the code I've come across so far. ...

AngularJs gm.datepickerMultiSelect is experiencing an issue with dates

I am currently working on implementing the gm.datepickerMultiSelect module in AngularJS. I have encountered an issue with a day offset when selecting a date and have pinpointed the line in the library that is causing the problem: var dateVal = Date.parse( ...

Guide on executing a function exclusively when the state of a service variable changes within an Angular4 component

In my InfoFormService, I have a variable called isInValidating that is initially set to false. This variable becomes true when the component calls the validateEmail(email) function as shown below. @Injectable() export class InfoFormService { private ...

Unable to update state in my React app when clicking on a button

There is a requirement for a button click to filter the job-card array by one specific category. For example, clicking on the button "Marketing" should only show jobs from the array that have the property "jobstags: Marketing". I followed a similar procedu ...

What is the reason behind the failure to update the state via a reducer and Object.assign?

I'm attempting to develop a reducer without utilizing ES6. It's an outmoded PHP application that lacks a build process for transpilation. I am initializing the state: let defaultState = { accountTypes: { individual: { c ...

JavaScript's addition function is not functioning properly

Does anyone know how to calculate the sum of these variables? var totalPrice = document.values.T1.value; var pounds = document.values.T2.value; var serviceFee = 5.00 var counter1 = 0; var counter2 = 0; var processing = 0; var shippingCost = 0; var ...

React: Error - Unable to use this.setState as a function

When attempting to pass a value from the Child Class to the Parent Class and set it in the Parent's state, I encounter the following error: TypeError: this.setState is not a function Parent Class class Header extends React.Component { constr ...

Trigger Ionic's go back function when the hardware back button is clicked within the message app

Currently, I am utilizing the cordova-sms-plugin to integrate the native SMS app within my application. However, I have encountered an unexpected behavior where clicking the hardware back button in the SMS app leads back to my own app and triggers the Io ...

Using JavaScript for Text Processing on Disk

Currently, I have a set of HTML files that require automated processing such as regex replacements and more complex actions like copying specific text blocks from one file to another. I am considering creating a series of scripts to handle this processing ...

Queries with MongoDB RegEx fail to return any matches if the search string contains parentheses

When trying to implement case-insensitivity using regex, it seems to work well for plain strings. However, if special characters like parenthesis are involved in the search query for the name, the database returns no results. For example, a search for "Pu ...

Locating the value of a data attribute from a distant parent div using jQuery

How can I access the closest div from an anchor tag that has a data-id attribute without using multiple parent() methods? Even though .parent().parent().parent() works, I am trying to find a better solution. <div class="panel panel-default" data-id="@ ...

Exploring the TypeScript compiler API to read and make updates to objects is an interesting

I'm delving into the world of the typescript compiler API and it seems like there's something I am overlooking. I am trying to find a way to update a specific object in a .ts file using the compiler API. Current file - some-constant.ts export co ...

The data structure '{ one: string; two: string; three: string; }' cannot be directly assigned to a 'ReactNode'

Here is the Array of Items I need to utilize const prices = [ { name: "Standard", price: "149EGP", features: [ { one: "Add 2500 Orders Monthly", two: "Add Unlimited Products And Categories", three: "Add 20 other ...