Issue with ng-model not appearing to establish a connection

Attempting to transfer values from input elements back to the controller using ng-model.

Tried assigning email to the ng-model, but upon logging it to the console, it showed as undefined.
Investigated these two resources:

  • Why is my ng-model variable undefined in controller?

Even when utilizing the dot notation, no output shows up on the console whatsoever. (not even 'Email: ')

The only error message received is:

TypeError: Cannot read property 'email' of undefined

HTML:

<ion-view title="Register" hide-nav-bar="true" nav-transition="none" id="page9">
    <ion-content padding="true" class="manual-ios-statusbar-padding" scroll="false">
        <form id="register-form4" class="list">
            <ion-list id="register-list4">
                <label class="item item-input" id="register-input7">
                    <input type="email" ng-model="reg.email" placeholder="Email">
                </label>
               <label class="item item-input" id="register-input9">
                   <input type="password" ng-model="reg.password" placeholder="Password">
               </label>
           </ion-list>
           <a ui-sref="tabsController.myTrips" id="register-button7" ng-click="register()" class="button button-positive  button-block">Create Account</a>
           <a ui-sref="login" id="register-button8" class="button button-positive  button-block button-clear">Back</a>
           <div ng-show="isError">{{ loginError }}</div>
       </form>
   </ion-content>
</ion-view>

Controller:

.controller('registerCtrl', ['$scope', '$stateParams', "$firebaseAuth",
function ($scope, $stateParams, $firebaseAuth) {
    $scope.register = function() {
        var email = $scope.reg.email,
            password = $scope.reg.password;

        console.log("Email: " + email);
        console.log("Password: " + password);

        // ...
    }
}])

Additionally, experimented with changing the HTML input type (from email to text) but the same error persists.

Answer №1

It seems like the issue lies here:

You are utilizing $scope.reg.email, yet you have not set up $scope.reg. Within your controller initialization, make sure to include a line similar to this:

$scope.reg = {};

Without that, $scope.reg remains undefined and triggers the "Cannot read property 'email' of undefined" error.

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

Picture fails to load on Ionic app on the device

Currently, I am utilizing Ionic 3 for my project. The location of the images file is \src\assets\img. This pertains to a basic page implementation. export class BasicPage { items = []; constructor(public nav: NavController ,private adm ...

We could not find the requested command: nodejs-backend

As part of my latest project, I wanted to create a custom package that could streamline the initial setup process by using the npx command. Previously, I had success with a similar package created with node.js and inquirer. When running the following comma ...

How can I use MongoDB updateOne to retrieve the newest document instead of the oldest one?

Apologies for the elementary question, but I am determined to make this code function properly. When using the .updateOne() function in node.js to update my mongo database, I leave the parameters blank thinking it would update the most recently added docu ...

Tailwind CSS compilation failure | Unexpected token found at 26:33 in Acorn

While attempting to implement tailwindcss using default CSS, an unexpected issue arose... tailwindcss 2.0.2 ? Building from default CSS... (No input file provided) ? SyntaxError: Unexpected token (26:33) at _class.pp$4.raise (C:\xampp& ...

Transmit data in JSON format using jQuery's AJAX function

What could be causing the PHP not to retrieve my links array? function check_links() { $matches = $this->input->get('links'); if($matches == true) { echo json_encode('matches is true'); } el ...

Modifying the class of multiple images within an array

I am excited to share my first post here and express my gratitude for all the solutions I have found on this platform. I encountered an issue with using .removeClass and .addClass in my recent program. I am loading multiple pictures into an array called F ...

Sending a property to a function in Redux for action creation

I'm currently facing an issue with passing the ID number as a prop into my action creator function when using an onClick event. I've successfully used this syntax in the past with setState(), but for some reason it's not working for me now. ...

Is concealing content using Javascript or jQuery worth exploring?

While I have been hiding content using display:none; in css, there are concerns that Google may not like this approach. However, due to the needs of jQuery animations, it has been necessary for me. Recently, I have come across a new method for hiding conte ...

The $or operator in mongoose falls short in providing complete data when paired with the find() method

I am currently utilizing the find method in conjunction with the $or operator to search the database for any duplicate data within this specific line. const duplicate = await NewItemsData.find({ $or: newItems }); Upon inspecting the variable in the consol ...

Tips for creating a floating navbar with separated lists using Bootstrap 4

Struggling to position my navbar to the right and separate the list within the navbar. Despite multiple attempts, I can't seem to get it right. Here is a snippet of the code I've been working on: here is what I'm trying to achieve $def with ...

Has the jQuery plugin object misplaced a variable?

I am in the process of developing a basic plugin using jQuery. My current approach involves creating private functions and storing variables within the jQuery object itself. (function($) { var somePrivateFn = function() { alert(this.x); } ...

Tips for successfully linking an ng-click function with an ng-repeat iterator

I'm working on an AngularJS snippet that shows a pagination bar on my website. The $scope.PagesOnBar object contains an array of numbers (1, 2, 3) that are displayed on the pagination bar. However, I'm having trouble with the ng-click attribute w ...

Utilize PHP to import an HTML file with JavaScript code into MySQL database

I've been attempting to use JavaScript to retrieve my location, but I'm facing an issue where when I click submit, the data is not getting entered into the page action.php. geolocation.php <form action="action.php" method="post"> < ...

What could be causing MS browsers to transform my object array into an array of arrays?

Noticing an interesting behavior with Microsoft browsers especially when dealing with data returned from our product API. It seems that the array of 52 product objects is being transformed into several arrays, each containing only 10 objects. Our error tr ...

Having difficulty with checkboxes in Vue.js: selecting one checkbox selects all, and struggling to pass dynamic data as the value

Currently, I am facing a complex issue related to dynamic checkboxes in Vue. This is the current state of my code: <table class="table table-striped"> <thead> <tr> <th>Student</th> & ...

I successfully linked expressjs, nodejs, reactjs, and mysql in my project. I'm puzzled as to why everything runs smoothly after I restart my express server, but encounters issues when I refresh the page

express path users.js var express = require('express'); var router = express.Router(); const connection = require('./MySQL.js') /* Accessing user data. */ router.get('/', function(req, res, next) { connection.connect() ...

Generate the page content first and then dynamically refresh it using AJAX while sticking to the same template HTML

Imagine you have a "Story View" on your website, which is essentially a web page generated using Python/Django. At the bottom of this page, there's a list of comments that are displayed within the "View Story" template by Django's templating syst ...

Testing Components in Vue: A Guide to Mocking Vue Components

I have experience using React Testing Library, but I haven't used Vue Testing Library yet. I want to avoid using mount or shallowMount when testing components in VTL and figure out how to provide a stub instead. When testing a component like Componen ...

Tips for achieving JSON formatting with JavaScript or jQuery

To achieve the desired output format, I am required to transform the provided input json. input json: [ { "key a": "value alpha" "key b": "value beta" "key c": "value gamma& ...

select elements from array by ObjectId

Here are two arrays that I'm working with: const people = [{_id:ObjectId("6274fb5b82bcc9b2ccc0a361"), name:p1, age:10}, {_id:ObjectId("6274fbc382bcc9b2ccc0a362"), name:p2, age:15}, {_id:ObjectId(" ...