Error message: ".then uncaught in promise with undefined value"

myFunction() {
    this.initiateTSOAddressSpace().then(this.launchApp);
    return "placeholder text";
}

sendData(contentURL: string) {
    let response = fetch(contentURL, {
        method: "POST",
        credentials: "include",
        headers: {"Accept": "application/json"}
    })
        .then(res => res.json())
        .catch((error) => {
            console.log("An error occurred: " + error);
        });
    return response;
}

getKeyForServlet(result: any) {
    return result.servletKey;
}

launchApp(result: any) {
    console.log(this.getKeyForServlet(result));
    let url = `${this.BASE_URL}/tsoAp/app/${this.getKeyForServlet(result)}`;
    console.log(url);
    return this.sendData(url);
}

Whenever I execute the above code, it throws an ERROR Error: "Uncaught (in promise): TypeError: this is undefined. This issue arises during the execution of ".then(this.launchApp)"

Answer №1

Make a small tweak in the code snippet below to test its impact

Modify the following:

sayHello() {
    this.startTSOAddressSpace().then(this.startApplication);
    return "filler";
}

to

sayHello() {
    this.startTSOAddressSpace().then(d => this.startApplication(d));
    return "filler";
}

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

The Google timezone API is displaying an inaccurate daylight saving offset

London now has an additional +1 hour of daylight saving time. I made a request to the Google timezone API for the London timezone, but unfortunately, it is not displaying the correct time. https://maps.googleapis.com/maps/api/timezone/json?location=51.507 ...

Automatically populate a dropdown menu with options based on the user's birth date

I successfully managed to populate the drop-down fields for months, days, and years. Furthermore, I was able to calculate the age of the user; however, I have restricted it to a maximum of 13 years. Check out the code snippet below: $('#reg-yr' ...

Exploring Virtual Reality with the Oculus Quest2 and Three.js

Currently, I am working on a project using Oculus and three.js to create a virtual reality experience. To test the functionality, I decided to try out the official sample provided. Here is the link to the official sample. My intention was to access the s ...

What changes can I make to the script in order to display every element from a MySQL query using PHP, MySQL, JavaScript,

Enhanced Multiple Dropdown Selection Using Ajax In the following scenario, we have a webpage featuring a multiple dropdown selection that interacts with a MySQL database. By choosing options in the dropdowns labeled site, menu, and category (categ), a que ...

Older browser compatibility for Flexbox flex-flow alternative

<template> <div> <h2>Kanal Listesi</h2> <div class="container"> <div v-for="(channel,index) in channels" :key="index"> <div v-if="channel.ChName"> <img :src="'h ...

Having trouble with data retrieval from MySQL using PHP and Angular on certain mobile devices, although it functions properly on desktops and laptops

The data retrieved from the mysql database is functioning properly on desktop and laptop, but not on mobile devices. The following HTML code is present in the html file: <table class="table table-default"> <thead> <tr> & ...

The async pipe is failing to function properly when used with the same observable

I'm facing an issue with the async pipe in my view as it's not loading any data dynamically. On my page, I need to change observable values multiple times such as reloading the page, loading more values, and updating news content based on differ ...

In TypeScript, enhancing an interface with additional properties

Currently, I am working on an Angular project and have developed this interface to display some data: export interface UserData { name: string, vorname: string, strasse: string, plz: string, ort: string, handynummer: string, telefonnummer: s ...

Configure the input to accept integer values

This page that I have developed is designed for entering Latitude and Longitude values. <div class="container "> <form class="entry"> <div class="aligncenter"> <h5 style="color:MediumTurquoise; font ...

Transforming a hierarchical array into a string based on a specific condition

Seeking assistance in properly formatting data using the reduce method const testData = { a: [1], b: [2, 3, 4], c: [] }; Objective is to convert to: a=1&b=2,3,4 Current output: a=1&b=2,3,4& const createUrlString = params => Object.key ...

Is there a way to execute a function prior to the MatTabChange event?

Within my mat-tab-group, each tab contains its own component with a unique state. I utilize a hasChanges property to track if there are any pending changes in the component that need to be saved. I am currently facing the challenge of notifying the user w ...

What is the best way to retrieve multiple elements by class and change their innerHTML?

Encountering an issue with calling multiple elements of the same class using .innerhtml. Here is the URL I am dealing with: When running the following code in Chrome console, this is the output: document.getElementsByClassName('a-size-small a-color- ...

Can someone provide an explanation of the Typescript peerDependencies in Angular, specifically comparing versions tslib 1.* and 2.3.*?

I am in the process of starting a new angular project, but I'm facing difficulties in importing the localStorage feature. I referred to an existing project that utilized localStorage in the following way: import { Injectable } from '@angular/core ...

When using node.js and express, attempting to send an email with the packages 'nodemailer' and 'nodemailer-handlebars' may result in a TypeError being thrown, specifically [ERR_INVALID_ARG_TYPE]

I am encountering an issue while attempting to send an email using an HTML template located in the 'view' folder within the same path. The HTML template is named 'index.handlebars'. Despite believing that the path is correct, I am recei ...

The Material UI Checkbox is displaying duplicate values within a single instance

Using React and Material UI checkbox I want the checkbox to update a specific value in the state when it's checked. While everything seems to be working fine, I've noticed that on the first 2 clicks of the checkbox the state doesn't update ...

Get JSON data through AJAX using two different methods

Help needed: JSON request issue with XMLHttpRequest var xhr = new XMLHttpRequest(); function elenco_studenti() { var url = "/controller?action=student_list"; xhr.responseType = 'text'; xhr.open("GET", url, true); xhr.onreadystat ...

Is there a way to retrieve the JavaScript Console response code using Python and Selenium's execute_script method?

I am running a JavaScript fetch request in the Chrome developer console using Selenium's execute_script() function. The request performs as expected, but I want to set up a function that can verify if the response is a 403 status code. Is there any Se ...

Utilizing the button's id to display a partial view within Rails

I am working on a view that showcases a partial containing a list of events created by a user, each with an edit link alongside. My goal is to have a form partial appear below the event when the 'edit' link is clicked. To achieve this, I have su ...

Changing the hover color of an Angular Material MD Button

<div class="non-active" layout layout-align='space-around center'> <md-button ng-click="$ctrl.widget.type = 'chart'; $ctrl.validateForm()" layout='column' ng-class="{selIcon : $ctrl.widget.type == ' ...

Obtain the list item using jQuery from the delete image within a nested

As I'm on the brink of solving this issue, I'm encountering difficulty in extracting the outer html from my <li>. The method I use to add my <li>'s to a <ul> is like so: function addTab() { tabs.append('& ...