The Angular UI dialog promise is triggered only when the dialog is reopened

Within the controller that triggers the dialog, I have:

$scope.openDialog = function () {
    var options = dialogOptionsFactory.build('/my/route/file.html', 'ChildController');
    var d = $dialog.dialog(options);
    d.open().then(function (result) {
        if (result) {

            // THIS ACTION IS DELAYED UNTIL DIALOG IS REOPENED!
            $scope.myresult = result;

        }
    });
};

In the dialog controller, the code looks something like this:

listModule.controller('ChildController', ['$scope', '$rootScope', 'dialog', function ($scope, $rootScope, dialog) {

$scope.uploadComplete = function (ifrm) {
    var response = angular.element(ifrm).contents().find("body").text();
    var responseObj = eval("(" + response + ")"); //Parentheses are necessary to convert JSON to JS object.
    $scope.close(responseObj.Data);
};

$scope.close = function (result) {
    dialog.close(result);
};

}]);

Why does the "then" promise not trigger until after reopening the dialog?

Update: I included additional details that I believe could be relevant. The data retrieval is from a concealed iframe's body. The promise functions properly when $scope.close() is directly called. This suggests there may be an issue with the iframe or passing back an object to dialog.close().

Answer №1

Not wanting to boast, sirhc refrained from posting his brilliant solution as an official answer. Allow me to do the honors! The key was encapsulating the function call within $scope.apply() to immediately alert AngularJS.

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

exciting, showcasing a dependency map using svg within an html5 environment

I am working on creating a polygon background for my menu, which needs to be responsive in design. Here is an example of what I am trying to achieve: example image. Should I use JavaScript to listen for size changes and adjust the points for the polygon e ...

Testing factories with Jasmine and Angular: A step-by-step guide

After conducting thorough research online, I have come up empty-handed in finding a solution to my issue. Essentially, I have a factory declared in the following manner: angular.module('puFactories').factory('RestFactory', function ($h ...

What is the process for using Selenium and Java to upload a file via an 'input' element with the type "hidden"?

I am facing a challenge with using Java Selenium to upload a file in the input element provided (upload element). <input type="hidden" ng-model="model[options.key || index]" id="formly_21_fileupload_args_content_substrate_surface_media_document ...

open a new window with a reference based on the name

In order to obtain a reference to the currently open window, I utilize the following code: var refWindow = window.open("mypage1", "name_mypage"); If I wish to close the window, I simply use this command: refWindow.close(); When I refresh the screen (by ...

Analyzing Passwords for Redirection

Greetings to all! I trust everyone is doing well. I have developed a react application that features 2 password fields, each with validation using regular expressions. Upon successful validation of both passwords, the application will automatically redirec ...

What is the best way to showcase a single <ul> list in an infinite number of columns?

Utilizing Django on the backend, I aim to showcase the list below in an unlimited number of columns with overflow-x: auto. <ul class="list"> {% for i in skills %} <li>{{i}}</li> {% endfor %} </ul> Example Result: 1 7 ...

Deciphering JSON File Paths

I'm having trouble finding the correct path to a local file. My directory structure is as follows: Resources -> data -> file.json js -> folder -> script.js html -> folder -> file1.html I ...

JSON.Parse function does not return a valid value

I'm currently developing a polling system. Once a user submits their answer choice, I expect to receive JSON data containing all the answers for display purposes. Upon submitting the AJAX form, the JSON response is as follows: [{"answer_1":0,"answer ...

How can I dismiss a popup confirmation in React?

The confirmation popup should close when clicking anywhere outside of it. However, the popup does not disappear as expected when the outside area is clicked. Additionally, I am getting the error message "Line 2:8: 'Backdrop' is defined but never ...

Implementing the MVC pattern in the app.js file for a Node.js and Express web application

After completing several tutorials on nodejs, mongodb, and express, I have gained a solid understanding of the basics such as: The main controller file being app.js. Third party modules stored in their designated node_modules directory. Template files pl ...

What is a more effective method for linking values with variables in an object?

Can you suggest a more efficient way to write this in JavaScript? let foo; if(bar) { foo = bar.value; } I am attempting to prevent a react error from occurring when `bar` is null if I were to use const foo = bar.value. ...

Sending information to a child component causes the parent's data to be modified as well

Transferring information from the parent to the child component has always been easy for me. However, I recently encountered an issue where updating the data in the child component also updates the data in the parent component simultaneously. Now, I am loo ...

Change the chart.js labels every time I make changes to the chart

I've been using chart.js to generate dynamic charts. While I can create different types of charts and manipulate the data displayed, I'm struggling with updating the labels. Below is my code snippet showcasing how I update the data: const color ...

A JavaScript or CSS file within an HTML document

I understand this may seem like a silly question. However, out of curiosity, is there a way to upload an HTML file (with a .html extension) as a JavaScript or CSS file (renamed with a .js or .css extension), specifying the type header as either HTML or js ...

DataTables.Net Buttons not appearing in the interface

I have a basic MVC project that utilizes BootStrap4 and dataTables.Net. When the page loads, an Ajax call is made to fetch data for a table. However, despite following the documentation, I'm unable to get the buttons to display on the page. Everything ...

How to effectively manage the default API quota in YouTube Data API v3 while ensuring requests are made every 60 seconds

Recently, I've encountered a challenge concerning the management of the default API quota for YouTube Data API V3, which allows 10,000 daily requests. In my JavaScript application, I need to fetch the number of subscribers and concurrent viewers every ...

Issues with jQuery .click and .html functions not functioning as expected

Does anyone have experience creating a game with jQuery? I can't seem to get the options after the first choice to work. Sorry, I don't have a working example at the moment. --- jQuery --- $(document).ready(function() { $(".console"). ...

Steps for adjusting the structure of an array of objects according to the ParentID

I need to reorganize an array of objects based on a field called ParentID. Here is an example dataset: var JsonVal = "data": { "Factorid": 197325, "orders": [ { ...

creating a value and finalizing on the yield operation

Despite my attempt to use es6 generators to set the value/done as I want, I am struggling to achieve the desired outcome. Whenever I try to set a value, it ends up in the "value" field, while the generator always returns "done: false" when I am actually ai ...

Conflicts arising between smoothState.js and other plugins

After successfully implementing the smoothState.js plugin on my website, I encountered an issue with another simple jQuery plugin. The plugin begins with: $(document).ready() Unfortunately, this plugin does not work unless I refresh the page. I have gone ...