How to assign the value of one property to another property within an object using AngularJS

Is this a silly question?

$scope.registration = {
        email: "",
        userName: "",
        password: "",
        confirmPassword: "",
        firstName: "DummyFirstName",
        lastName: "DummyLastName"
    };

I want to set the userName to be the same as the email.

I attempted the following:

$scope.registration = {
        email: "",
        userName: email,
        password: "",
        confirmPassword: "",
        firstName: "DummyFirstName",
        lastName: "DummyLastName"
    };

but I received an error saying it does not exist.

Answer №1

One way to achieve this is by:

$scope.registerUser = {
    email: "",
    password: "",
    confirmPassword: "",
    firstName: "SampleFirstName",
    lastName: "SampleLastName"
};
$scope.registerUser.username = $scope.registerUser.email;

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

Unable to assign an ID to an element in JavaScript, as it will constantly be undefined

Is there a way to automatically generate unique IDs for jQuery objects if they don't already have one? I need these IDs for future requests. I wrote the following code, but it doesn't seem to be working. The ID's are not getting set and the ...

I am having trouble inserting a table from a JSON object into an HTML file

getJSON('http://localhost:63322/logs', function(err, data) { if (err !== null) { alert('Something went wrong: ' + err); } else { //var myObj = JSON.parse(data); // document.getElementById("demo").innerHTML = myObj.ad_soy ...

The function L.featureGroup.subGroup() is a powerful tool provided by Leaflet and Cart

I'm struggling with getting the subgroups to function correctly. The clusters display, but when I deactivate layers, the clusters do not update accordingly. Moreover, activating a layer turns on all underlying points. How can I ensure that the subgrou ...

Manipulate the content of an element based on its value using Javascript

Let's customize text based on user selection. Take a look at the select options below: <select onchange=Modify(this.value)> <option value="1">Apple</option> <option value="2">Banana</option> </select> < ...

Require assistance with handling Ajax when a function with an Ajax call is repeatedly invoked

I am seeking guidance with ajax as I am still new to it. A problem arises when the same ajax call is made multiple times before the previous one completes its execution, resulting in an empty pop-up on the user interface. How can this issue be resolved? Es ...

Issues with AJAX file uploads in Django

I'm encountering an issue while attempting to upload files using Ajax in Django. My approach involves utilizing FormData in Javascript. However, the problem lies on the server side. The files are expected to be received in request.FILES, but they are ...

Firebase onSnapshot error when retrieving data from Snapchot

Having trouble with Firebase authentication. Whenever I try to authenticate with Firebase, I encounter this error message: App.js:27 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'onSnapshot') Here is the code sni ...

What is the best method for storing and accessing audio files that users upload in my MERN application?

I am developing a MERN application and am looking to implement a feature that allows users to upload audio files. I have read that storing the files directly in the database or within a folder inside the app is not recommended. I need a solution that en ...

What is the best way to nest a v-for inside another v-for in Vue.js?

BaseAccordion.vue <template> <div class="wrapper"> <div class="accordion"> <input type="checkbox" @click="toggleItem" /> <h2 class="title"> <slot name="title"></slot> </h2> ...

Obtain asynchronous state in VueJS without the need for intricate v-if conditions

I am working on an application that heavily relies on Vue-Router and Vuex for state management. Within the Dashboard component, important user information is displayed. This data is fetched asynchronously from a database by Vue and then stored in Vuex. T ...

Exploring through an array tree structure?

My menu displays the "selected" array as options. When an option is selected, its branches are rendered as new options. To keep track of the traversal, I create an array called select. For example, if someone selects the 3rd option, then the 1st option, a ...

Is there a way to add a new button each time a different model is inserted by someone?

My goal is to add a new button each time a new data for a car make is added. However, currently the button keeps getting appended to the same button instead of creating a new one. How can I ensure that a new button is created for each data entry? $.ajax ...

The Vue component with the export default directive could not be located

Whenever I try to create a dashboard component, I keep encountering the same error in my command prompt. "export 'default' (imported as 'DashboardLayoutComponent') was not found in '@syncfusion/ej2-vue-layouts' Has anyo ...

Feeling uncertain about how to utilize AJAX using the XMLHttpRequest object

The JavaScript function is: function loadData() { const xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (xhttp.readyState == 4 && xhttp.status == 200) { const data = xhttp.responseXML.documentElement.getElement ...

Having trouble uploading to Cloudinary server using AngularJS

I'm facing a CORS error when using ng-file-upload with the Cloudinary server. I've checked my code multiple times, but still can't figure out what's causing the issue. Here is the code snippet: Upload.upload({ url: "h ...

Angularjs: The Art of Loading Modules

I am facing an issue while trying to load certain modules. controller1.js: angular.module('LPC') .controller('lista_peliculas_controller', ['$scope', function($scope) { $scope.hola="hola peliculas"; }]); And ap ...

Implement Clip Function with Gradient Effect in JavaScript on Canvas

Trying to incorporate the clip() function within the canvas element to create a unique effect, similar to the one shown in the image. I have successfully achieved a circular clip, but I am now aiming for a gradient effect as seen in the example. How can th ...

Unable to align text within a DIV using CSS

Recently, I started learning jQuery and building my own website. You can find my project on JSFIDDLE. The issue I'm facing is that when hovering over a new div, the text extends beyond the borders of that div instead of staying within it. I've sp ...

Implementing a fixed value instead of a variable in the HTML for a directive attribute

I am looking to implement a directive that requires an attribute. I want this attribute to always be set to true without the need for a scope variable. However, I suspect that using "true" directly as the attribute value may be incorrect, as it might be in ...

What is the process for combining two distinct geometries with different materials into a single entity in three.js?

I created a 2D square line diagram followed by another square diagram with a sample image in the center position. However, one of them is visible while the other is hidden. I used two different geometries and materials - one with a line-based material se ...