Angular: controller's property has not been initialized

My small controller is responsible for binding a model to a UI and managing the UI popup using semantic principles (instructs semantic on when to display/hide the popup).

export class MyController implements IController {
popup: any | undefined

onShow(context: any) {
    this.popup = $(context)
    console.log('this.popup', this.popup)
}

onHide() {
    this.popup?.popup('hide')
}
}

After successfully showing the semantic popup, the reference is stored in this.popup. Upon inspecting with console.log(), it confirms that this.popup now retains the reference to the popup for future use. However, upon clicking the button to close the popup and invoking onHide(), this.popup becomes undefined. Despite checking whether a constructor or any Angular lifecycle hooks like onChanges or onDestroy are being triggered through breakpoints, nothing seems to be happening. Why does this.popup become undefined despite being explicitly set earlier?

EDIT: Additional information as per request: We utilize semantic UI, and this is the button that triggers the popup to open, thus calling vm.onShow(). In this context, "context" from the aforementioned controller refers to the button that initiated the click event.

<button class="ui icon basic button" ng-class="{ yellow: !vm.model.allActive }"
    ng-click="vm.model.open(attribute.value)"
    jq-init-popup-fixed="{ inline: true, position: vm.model.position, on: 'click', onVisible: vm.onShow }">
<i class="icon semantic-icon filter" style="padding-left: 1px;"></i>

This specific button serves as the trigger for closing the popup, activating onHide() and instructing semantic to conceal the popup if the controller doesn't lose its reference.

<div class="ui actions right floated button" ng-click="vm.model.close(); vm.onHide()">
            <span translate="POPUP_BTN_OK"></span>
        </div>

Answer №1

After some investigation, I finally cracked the code. The usage of onShow() differs from onHide(), resulting in a distinct context and causing the nonexistence of this.popup.

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

Passing an array from PHP to JavaScript using AJAX

Here is the code snippet on the server side: <?php header('Content-Type: text/html; charset=utf-8'); require "../general.variables.php"; require "../functions_validation.php"; require "../functions_general.php"; require "../../db_con.php"; $ ...

What is the best way to restrict the size of a table that is filled with data from a database?

Currently using a combination of React, Node, Express, and Postgres to populate a table with data retrieved from Postgres. The issue arises when the table becomes overly long, prompting the need to display only 5 rows at once while adding a scroll bar for ...

Reorganizing the layout of a React grid in response to changes in screen size

Currently, I'm facing a challenge in creating a container for a React app that includes a Highcharts chart and three textboxes. My struggle lies in getting the three textboxes to adjust and rearrange beneath the chart component when resizing the scree ...

The $save function does not operate properly; although the call is successful, it fails to trigger the .then() method

Attempting to place a call that POSTs an array using $save, but encountering issues with callback function execution. Despite receiving a 200 response, both success and failure callbacks are not triggering. var endpoint = "my valid url"; var ...

Transmitting information to the service array through relentless perseverance

I need assistance finding a solution to my question. Can my friends help me out? What types of requests do I receive: facebook, linkedin, reddit I want to simplify my code and avoid writing lengthy blocks. How can I create a check loop to send the same ...

In JavaScript, find a value in an array and substitute it with the value from the

One of my tasks involves manipulating a string variable in the following manner: domNodes += '<a href="javascript: void(0);" data-role="node_jump" data-node="'+this.tagName.toLowerCase()+'">'+this.tagName + "</a>" + " & ...

Trying to decide between using a Javascript or HTML5 PDF Editor?

I am in need of a solution that enables users to edit PDF files directly on an ASP.NET web page. This functionality is intended for creating templates and adding blocks/form fields to existing PDFs, complete with rulers and other necessary features. Desp ...

A guide on iterating through a JSON object fetched using Http in Angular 2/Typescript

I am attempting to extract specific data from my JSON file using http. The structure of the JSON is as follows: [{"name":"Name1","perc":33},{"name":"Name2","perc":22},{"name":"Name3","perc":41}] To loop through this retrieved object, I use the following ...

FlexNav excluding

I have implemented FlexNav for my website navigation. The demo I used sets the width of top-level menu items to 20%, which works well with five menu items. .flexnav li { . . . width: 20%; } However, in my menu, the text lengths of the top ...

Checking File Upload Progress in HTML and PHP

As a newcomer, I've been struggling to find a solution to an issue I'm facing. My concern is regarding a form that is meant to upload a file and send it via email. How can I display the progress status of the file being uploaded? It seems that us ...

Searching for substrings in NodeJS using Express

In this code snippet, I am using Express JS and AES256 encryption to encode and decode simple text strings with a predefined key. The Express JS web server is set up to display specific elements based on the URL content. For instance, if the URL was abc. ...

How is it that in TypeScript, a potential numeric value in an interface can be transformed into an impossible numeric value in a class implementation?

Encountered a surprising behavior from the TypeScript compiler today. Unsure if it's a bug or intentional feature. If it is indeed intentional, I would like to understand the reasoning behind it. The issue arises when declaring an interface method wi ...

What are the differences between an optional property and a non-optional property?

Let's say I am working on creating an array of type CoolObject. What would be the better approach if some objects have the property format, while others do not? // Option 1 export interface CoolObject { name: string; color: string; ...

How to apply props conditionally in VueJS?

I have a component called blogPost (Component A) that is imported in another component named B. When a button in Component B is clicked, Component A opens in a modal. There are two different use cases for this scenario. 1. One case requires passing 2 prop ...

Utilizing pop-up info boxes

After thoroughly reviewing the documentation on Imagemapster's website and browsing several posts, I am still struggling to get the tooltips working correctly. I attempted to share my HTML and JS code on jsfiddle.com without success, so I have provide ...

Is a 'Virtual DOM' included in React Native's architecture?

According to the ReactJS wiki page on Virtual DOM: React uses an in-memory cache of data structures to efficiently compute differences and update the displayed DOM in the browser. This allows developers to write code as if the entire page is re-rendered ...

What is the best way to retrieve the column that comes after a specific column?

I have a specific column and I want to extract the subsequent column in the dataset. nhood,column,variablecolumn Treasure Island,3,5 McLaren Park,1,2 Tenderloin,28,112 Lakeshore,14,8 Chinatown,15,103 Although I know the name of the second column, the na ...

Get rid of the arrow that is displayed when using the `time` input type in HTML5

Recently, I encountered an issue with the default HTML5 code snippet. My custom background looked perfect except for a pesky black arrow appearing on the right side. In this image, you can see the problematic black arrow that needs to be removed. I attemp ...

Error encountered while making an http get request for a node that returns JSON

I've been struggling with this issue for quite some time now. While I've come across similar problems on Stack Overflow, none of the suggested solutions seem to work for me. I keep encountering the following error message: undefined:1 SyntaxErro ...

When Vue is clicked, it appears to trigger multiple methods simultaneously

Currently, I am learning Vue and encountered a problem that I need help with. When using the v-on:click directive to call a method, all other instance methods are also called when the same method is used elsewhere. HTML: <div id="exercise"> &l ...