Issues have been encountered with the functionality of $rootScope

I am currently struggling with a code snippet in my loginCtrl.js file where I can't seem to get $rootScope to store the value of vm.userEmail.

app.controller('LoginCtrl', function($timeout, $q, $log, $rootScope /*$auth*/,   $location, $mdToast) {
    var vm = this;
    vm.loginMessage = '';
    vm.login = function(){
        $auth.login({
            $rootScope: vm.userEmail,
            password: vm.userPassword
    })  
  }
});  

I believe using $rootScope would be beneficial for handling certain conditions when a specific user connects.

if ($rootScope == '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="651c3a1c25d0d1108040c094b0608">[email protected]</a>') {
        data = [1,2,3,4]
    } else {
        data = [5,6,7,8]
    }

If you have any ideas, suggestions or corrections, please feel free to share them ;)

Answer №1

Think of $rootscope as a unique application context where you can add new values. Take a look at the code snippet below for an example of how it works:

app.controller('LoginCtrl', function($timeout, $q, $log, $rootScope /<em>$auth</em>/,   $location, $mdToast) 
{
    var vm = this;
    vm.loginMessage = '';
    vm.login = function(){
        $auth.login({
            $rootScope.userEmail : vm.userEmail,
            password: vm.userPassword
        })  
    }
}); 

You now have access to $rootScope.userEmail throughout the entire application.

If ($rootScope.userEmail == '[email protected]') {

    data = [1,2,3,4]
} else {
    data = [5,6,7,8]
}

Answer №2

rather than

$rootScope = someValue;

try

$rootScope.someValue= someValue;

For the second part of your code, attempt:

observe changes in $rootSchope.someValue

example:

$rootScope.$watch('$rootScope.someValue', function(newValue) {
    if (newValue='<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="71082e0831191e051c10181d5f121e1c">[email protected]</a>') {
        data = [1,2,3,4]
    }
});

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

Searching for different forms of multiple words using regular expressions

I have a value saved in a variable: var myvalue = "hello bye"; var myText = "hellobye is here and hello-bye here and hello.bye" Is there a way to check if different versions of myvalue are present in the text? I am currently using this pattern: hello ...

Exploring ways to overlay 2D text onto my Blender-created 3D model

Having created a 3D model with Blender, I am trying to overlay 2D text over the different meshes of the model. While I have successfully changed the colors of the meshes based on their indices using diffuse.color, I am struggling to draw text over my mesh. ...

extract the ng-model data and send it to an angular directive

In my current project, I have a specific situation where there are multiple text-boxes and when any of them is clicked, the corresponding ng-model should be displayed in the browser console. To achieve this functionality, I came up with the following Angul ...

Guide to creating JSDoc for a TouchEvent handler

Looking to improve my shorter-js codebase with JSDoc for TypeScript definitions, but hitting a roadblock. I've implemented the on() function using Element.addEventListener, working well so far. However, when passing a TouchEvent as a parameter for an ...

What is the best way to display a placeholder instead of the state's value when a page loads?

I'm having trouble displaying the placeholder of an input instead of its state value. When the page loads, it shows an empty select box because the testType state is null initially. How can I make sure that only the placeholder is shown instead of the ...

Validating phone numbers in Saudi Arabia for both mobile and landlines

I've been struggling to validate a Saudi Arabia phone number on my Bootstrap form, but I keep running into an invalid error. Here is the current regex pattern I am using: /^(009665|9665|\+9665|05|5)(5|0|3|6|4|9|1|8|7)([0-9]{7})$/ function ch ...

Every time I attempt to make a "post" request to the SailsJS server, I encounter a 403 CSRF Mismatch error

Having an issue with my sailsJS server. I am attempting to send a post request from a client on a different domain. I am sending _csrf from /csrfToken, but encountering a 403 csrf mismatch repeatedly. The client-side code appears as follows: $.ajax( ...

Issue when trying to use both the name and value attributes in an input field simultaneously

When the attribute "name" is omitted, the value specified in "value" displays correctly. However, when I include the required "name" attribute to work with [(ngModel)], the "value" attribute stops functioning. Without using the "name" attribute, an error ...

Error occurs when attempting to instantiate a class with parameters that do not match any available constructor signatures

I am attempting to encapsulate each instance of router.navigateByUrl within a class function, with the intention of calling that function in the appropriate context. However, I am encountering an error that states 'Supplied parameters do not match any ...

Dynamically removing buttons with JQuery

I am trying to dynamically add buttons to a page based on an array, but I'm running into a problem. Whenever I add a new name to the array, it prints out all of the buttons instead of just the one I added. I need help figuring out how to erase all the ...

Is your data coming in as NaN?

I am currently developing a basic webpage that has the capability to calculate your stake and determine your return, reminiscent of a traditional betting shop. As of now, I have successfully hard coded the odds into my page. However, while testing my code ...

Connecting Next.js to a Database: A Step-by-Step Guide

I am interested in developing an application similar to Samsung Health that will involve heavy querying on a database. I am unsure whether it would be more beneficial to create a custom server using Node.js (with Express.js) instead of using the integrate ...

Creating an app using Ionic 1 that features scrollable tabs with the ability to handle overflow

My current code snippet is displayed below. On smaller mobile screens, all 7 tabs are not visible at once and instead appear in two rows which looks messy. I want to modify the display so that only 3 tabs are visible at a time and can be scrolled through. ...

"An ng-repeat directive with a filter applied results in an empty

After successfully implementing the ng-repeat loop below: <div ng-repeat="einschItem in einschaetzungen.alldata | filter: { savedatum: lolatage[tagarrayindex].tagestring } | orderBy : '-savetimestamp'"> I wanted to check if the filtered r ...

Express.js receiving JSON POST data with AngularJS incorrectly interpreted as keys instead of values

I am facing an issue while trying to make a POST request with JSON data from angularjs to node/express. The problem is that all the data is appearing in the KEY of the req.body instead of as key value pairs. Although I found a similar question addressing ...

Setting a completion flag using a factory in AngularJS

I'm struggling to create a factory that can set a completion flag for a value within an object. The object in question looks like this: {"key1":"value1", "key2":"value2", "key3":"value3"} My goal is to retrieve and operate on the value associated wi ...

NextJs issue: Your `getStaticProps` function failed to return an object

I am currently developing a web application using NextJs. On one of the pages, I am trying to make an API call to fetch data and display it. However, during compilation, I encountered an error. The specific error message is: Error: Your `getStaticProps` f ...

Having difficulty placing a marker using google-maps-react

import {Map, GoogleApiWrapper} from 'google-maps-react' var React = require('react') class GoogleMapContainer extends React.Component { render() { return( <Map google={this.props.google} sty ...

IE9 presents a frustrating issue where the jQuery select box value is returning as

I've been battling a bug for over 2 hours now. My javascript code is supposed to generate a two-level select box for tasks and subtasks from JSON data. However, I recently discovered that this code doesn't function properly on IE9, and possibly ...

Looking to incorporate an Ajax feature that allows for updating dropdown menus in each row of the database

Please find below the UI screenshot highlighting the dropdown menu: What I am looking for? I would like the option selected in the dropdown menu to be updated for each specific row in the database using AJAX. Below are the codes I have written. As a beg ...