Issue "TypeError: Property 'email' is undefined" encountered while implementing AngularJS and Ionic

Below is the form structure that integrates AngularJS and Ionic:

<ion-modal-view class="game" ng-controller="PdfsmtpCtrl">

  <ion-header-bar class="bar bar-balanced">
    <a class="button button-icon icon ion-close-circled" ng-click="hideInformation()"></a>
    <h1 class="title">PDF-Export per Email</h1>
    <a type="submit" ng-click="getPdf(user)" class="button button-icon icon ion-checkmark-circled"></a>
  </ion-header-bar>

  <ion-content scroll="false" class="game">
        <div>
            <form novalidate class="simple-form">
              <label>E-mail: <input type="email" ng-model="user.email" /></label><br />
              <input type="submit" ng-click="getPdf(user)" value="Save" />
            </form>
        </div>
    </ion-content>

</ion-modal-view>

UPDATE: Here are the details of the AngularJS functions in use:

'use strict';

angular.module('app')
.controller('PdfsmtpCtrl', function ($scope, Pdfsmtp)
{   
    $scope.pdfsmtp = new Pdfsmtp();

    $scope.hideInformation = function ()
    {
        $scope.pdfsmtpModal.hide();
    };


    //joey: PDF to generate
    $scope.getPdf = function (user)
    {
        var user = angular.copy(user);
        var emailReceiver = user.email;
        
        var emailSubject = "<SubjectText>";
        var emailBody = "<BodyText>";
        var emailSender = "<EmailAddress>";
        var fileName = "<FileName.pdf>";
        var hostName = "<SenderHostName>";
        var contentType = "application/pdf";
        
     
        var doc = new jsPDF
        ({
            orientation: 'p',    
            unit: 'mm', 
            format: [210, 297],
        });
    
    //joey: Simon Bengtsson and his autotable
    doc.setFontSize(22);
    doc.setTextColor(23, 154, 85);
    doc.text(("<SomeText>"), 14, 15);
    doc.autoTable(
    {
        startY: 30,
        startX: 30,
        headStyles: {fillColor: [25, 141, 79] },
        footStyles: {fillColor: [25, 141, 79] },
        theme: 'grid',
        styles: 
        {
            overflow: 'linebreak',
            lineWidth: 0.5,
            lineColor: [25, 141, 79]
        },
        html: '#resultTable',
    });
    var finalY = doc.lastAutoTable.finalY || 20;
    
    doc.setTextColor(23, 154, 85);
    doc.text('Table:                   Signature:', 14, finalY + 20);
    var blob = doc.output();
    var dataUri = "data:" + contentType + ";base64," + btoa(blob);

    Email.send(
    {
        Host: hostName,
        Username: emailSender,
        Password: "<somepassword>",
        To: emailReceiver,
        Attachments : 
        [{
            name : fileName,
            data : dataUri
        }], 
        From: emailSender,
        Subject: emailSubject,
        Body: emailBody
        }).then($scope.hideInformation());
        
    } 
});

Upon clicking Save in the form, everything works smoothly as the user variable is passed along to the respective function.

However, upon clicking the submit icon in <ion-header-bar>, an error is encountered stating that the user variable is undefined:

TypeError: Cannot read property 'email' of undefined

To rectify this issue and be able to utilize the Submit functionality, what steps need to be taken?

Answer №1

It is important to properly initialize the user object to avoid potential issues with undefined properties.

$scope.pdfsmtp = new Pdfsmtp();
$scope.user = { 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

Guide to transform HTML into JSON with PHP

If you need to convert JSON to HTML, the JsontoHtml library can help. Now you want to convert existing HTML to JSON, and the following script was found: <script> $(function(){ //HTML to JSON $('#btn-render-json').click(function() ...

Converting 2D pixel art into 3D coordinates with ThreeJS

Attempting to display a cube generated in ThreeJS on an HTML canvas at a specific location has been quite challenging. The location is defined in pixels, for example (100,200). Unfortunately, the process of converting these pixel values into ThreeJS coord ...

All web resources need to be included in the web_accessible_resources manifest key

I'm encountering an issue with my Angular app. The error message on the client console reads: Denying load of chrome-extension://fiekimdgbphfmnlbiahcfdgcipcopmep/js/lib/angular/angular.min.js.map. Resources must be listed in the web_accessible_resour ...

Ways to output information via javascript/jquery

I am working on the following JS code. let myData=[]; for(let j=1;j<=Pages;j++) { $.ajax({ type: 'get', url: 'link.xml'+j, async: false, dataType: 'xml', success: function(data){ ...

How to create a responsive image that appears over a button when hovering in Bootstrap?

My goal is to display an image over a button when hovering. I've tried adding the .img-responsive class in Bootstrap while including the image in the HTML, but it's not working as expected with my current method of loading images. The buttons the ...

Managing the uploading of files when a new property is included directly from the JavaScript File Object

When processing files using the POST method, I am able to access the default information such as name, type, size, tmp_name, and error through PHP. However, the file being sent contains additional data that I need PHP to extract. https://i.sstatic.net/bGj ...

How can you set a $_GET variable without having to reload the page?

I have a table on my website that displays values for each row, and here's an example code snippet: //JAVASCRIPT <tr onclick="window.history.replaceState(null, null, 'myPage.php?ID=2');"> The URL changes with this code, but it doesn& ...

Discovering Unconventional Columns Through Sharepoint REST Api Filtration

I am working on recreating SharePoint's front end in my app and want to add columns to my table just like a user would in SP. The challenge I am facing is determining which columns were custom generated by the user rather than standard ones. Although ...

Deactivate the button for each package based on a specific PHP value

Are you looking to purchase a package or multiple packages? The available packages are displayed in the table below. I would like to implement a feature where once a user buys a package, the corresponding button for that package is disabled. Here is my cu ...

What is the best method for sending data from the server to a client-side JavaScript file?

Is there a way to send data from the server to a client-side JavaScript file without displaying it on the main screen using the innerHTML property? https://i.sstatic.net/YcsJq.png I've gone through several express.js tutorials but haven't found ...

Turning JSON into an array without needing to use a key can be achieved by simply

I'm facing a challenge with an array of objects in the following structure: [{ "X": "valueX", "Y": "valueY", "Z": "valueZ" }, { "X": "anotherX", "Y": "anotherY", "Z": "anotherZ" }] My goal is to transform this data into a two ...

Show data on television

My workplace recently acquired a few TVs that we plan to use as display screens for project-related information such as schedules, TO DO lists from web apps like Buildertrend, and accounting crystal reports in the form of dashboards or direct crystal repor ...

Using multiple 'ui-sref' directives within a single 'ui-sref-active' in AngularJS

HTML: <!-- Arrange --> <li ui-sref-active="active"> <a ui-sref="order" class="main_link"> <i class="fa fa-shopping-cart"></i>Order </a> <a ui-sref="order/create"><span class="plus">+</sp ...

Struggling to get Ajax to function on IE8 with dropdowns, while other browsers are working perfectly fine

My AJAX code functions properly in most browsers, however, it is not performing well in IE. While it successfully creates an XMLHTTPRequest object, the data retrieved from my PHP script is only returning an empty list! Check out my JavaScript code: < ...

Determining if an item is located within a nested scroll container

How can one detect if a specific element within a scrollable container is currently visible to the user's view (i.e. within the visible area of the scrolling parent)? Is there a universal method available that does not require iterating through all p ...

Looking to grasp the concept of calling inline functions within a React functional component

As a newcomer to React, I recently created a new view within my company. Following the example of many guides, I have utilized inline functions and function components exclusively. One common practice I have adopted is writing onClick events in this manne ...

The functionality of Bootstrap popover is not functioning properly

I'm trying to activate a popover when users hover their mouse over a div. Can I use a popover with a div, or am I missing something in my code? Here's what I have: <div class="grid-item content-text" data-toogle ="popover" data-content="Lorem ...

Delete a specific element based on its class by utilizing the parent() method

As I modify a jQuery validator, it adds a div to the parent element when an error occurs. My goal is to remove this inserted div with a specific class name from the parent. $(element).parent().remove('.removeThis'); Although I expected the code ...

Experiencing a 404 Error with a Specific Route in Node.JS Express

I'm running into some issues with my node.js express routes. As a beginner, I'm having trouble spotting where I've gone wrong. Despite looking at similar threads on Stackoverflow, I haven't been able to fix the problem. Is there anyone ...

Within the ng-repeat loop, every switch button undergoes a status change

Utilizing ng-repeat, I have implemented a feature to display multiple content with on/off buttons. However, when toggling the off button for a specific content, all button states are being changed instead of just the selected one. <div ng-repeat="setti ...