The callback for closing the $uibModal with a value will consistently result in undefined

Using ng-click="$widget.addItem()" in my template triggers a $uibModal.

Everything is functioning properly - opening, closing, etc.

The issue arises when trying to get the callback value from $modal.close($value). The function itself works correctly, the modal closes, and the promise success function is executed. However, it consistently returns undefined.


Controller for Component

app.component('list', {
    templateUrl: 'widgets/list.html',
    controllerAs: '$widget',
    controller: function($uibModal) {

        // Add item using modal
        this.addItem = function() {

            // Initialize and open $uibModal
            var modalInstance = $uibModal.open({
                component   : 'modalAddItem',
                size        : 'md'
            });

            // Promise from $uibModal
            modalInstance.result.then(function(params) {
                console.log(params)
                // ---> undefined 
            });
        }
    }
}

Template for Modal

<div class="modal-add-item">

    <div class="modal-body" id="modal-body">
        // Template content here 
    </div>

    <div class="modal-footer">
        <button class="btn btn-sm btn-default" ng-click="$modal.ok()">Ok</button>
    </div>

</div>

Component for Modal

app.component('modalAddItem', {
    templateUrl: 'widgets/modals/add-item.html',
    bindings: {
        resolve: '<',
        close: '&',
        dismiss: '&'
    },
    controllerAs: '$modal',
    controller: function ($scope) {

        this.ok = function() {
            this.close({item: 'picked item'});
        }

    }
});

Despite all efforts, the close function continues to produce undefined

Answer №1

It is recommended to utilize $value in place of item.

this.ok = function() {
  this.close({$value: 'selected item'});
}

close - A method to close a modal and provide a result. The result should be in the following format: {$value: myResult}

Visit Angular UI bootstrap

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

Stop the npm start command with a specific error message if the file is not found in the repository

Can the npm start process be stopped or cancelled if a specific file is not found in your codebase? I am looking to end the process if the file dev-variables.js is missing, preferably displaying a custom error message like "You are missing the dev-variabl ...

How can I prevent list items in jQuery Mobile from being truncated with ellipses?

Here is the list I am working with: <ul id="linksList" data-role="listview" data-inset="true" data-filter="true"> <!-- Dynamic contents! --> </ul> This list pulls its data from a local XML file (RSS feed). I am looking f ...

Unable to trigger JavaScript function from ASP.NET MVC HTML view

I am encountering an issue with my ASP.NET MVC project where I am attempting to call a JavaScript function to record a user's selection from a listbox. Despite duplicating the JavaScript function in multiple places, it is still not being found. What c ...

Receiving NaN in javascript when attempting to calculate the sum using a text input field

I am trying to calculate the total value by adding a fixed price with another value entered in a text input field. Here is the HTML code snippet: <%= f.text_field :hoursclass, id:"txt_hours" %> And here is the JS code snippet: $(function() { va ...

Is there a way to prevent the Pace js plugin from running on page load, but still have it execute during Ajax requests only?

I have successfully implemented the jquery pace plugin with a progress bar theme. Everything is working well, but I am looking to make it run only on ajax requests. I have tried various solutions found through research, but haven't had any luck. Belo ...

Cordova experiencing difficulty loading platform API

Lately, I've been facing a persistent issue with Cordova. Whenever I try to run it in the browser, an error pops up saying that the browser is not added as a platform. Even when I attempt to add the browser as a platform, another error occurs stating ...

How can you determine the number of elements that match in two arrays?

As a coding newbie, I'm looking to create a JavaScript function that compares two arrays and assigns a score based on the number of matching elements. However, when I attempt to run it in Chrome's console, I receive an error message stating that ...

The `pages` directory seems to be missing. Package error encountered while using NextJS

As I strive to create a NextJS executable application for Windows, an irritating error has arisen: (node:18500) UnhandledPromiseRejectionWarning: Error: > Couldn't find a pages directory. Please create one under the project root I assure you, th ...

Scaling Images using HTML and CSS

Hey there, I'm currently learning web development and running into a bit of trouble with creating responsive images. Can anyone give me some guidance on what changes I should make in the code below? Here's the HTML code: <div class="caro ...

Fixing the slide bar in React using styled components

In the early stages of creating a slider where cards (divs) can be moved left and right with a click, I encountered an issue. The onClick handler is functioning properly. However, upon running the project, I noticed that the cards start 230px away from the ...

"Implementing filtering logic for an array of objects with multiple conditions in a React application

I am looking to apply filters to a person list based on criteria such as city, job, age, and gender. How can I apply filters based on five conditions in React? I tried using filter chaining but it did not work for me. In the useEffect hook, I applied indiv ...

Unselecting a span in AngularJS: Switching selection to another span

Whenever I click on an item from my list displayed using ngrepeat, it generates another list specific to the selected element. My goal is to change the background color of the clicked element to indicate it has been selected. However, the problem arises wh ...

Make sure to verify if the mode in Angular is either visible-print or hidden-print

Here is a snippet of code <div class="row"> <div class="col-sm-12 visible-print"> Content (display in full width when printed) </div> <div class="col-sm-6 hidden-print"> Content (same as above but only half width when ...

Oops! The Vue star rating encountered an error because it couldn't read the length property of an undefined value at line 26 of listToStyles.js

Encountering an issue with the getRating function in Vue while using the Vue-star-rating package in Laravel. Unsure of what the problem may be. getRating(){ var pathArray = location.pathname.split('/'); v ...

Sending a Boolean value from a child component to its parent state in React JS

Within my application, I have implemented a login feature in the navbar component. However, I am encountering an issue with updating a variable in the main component upon successful login. Although I have successfully managed to set up the login functional ...

What is the proper way to transfer data from a file using npm's request package?

I'm currently utilizing npm's request module to interact with an API. The API specifications require that data be sent through a file using the @site.json notation when making a CURL request. For example: curl -X POST -d @site.json 'https ...

Is there a way to smoothly transition a FlatList while the keyboard is open?

At the moment, the appearance and animation of my messaging screen are as follows: However, I'm eager to enhance my messaging initial animation to lift up my flatlist like this (opens with scrolling): This is the code for the screen: // Code goes he ...

Unable to retrieve information from the API despite successfully establishing a connection

I have been attempting to establish a connection between backend Laravel and frontend AngularJS using an API and AJAX $http method. The API connection works fine, but I am facing an issue where the data is not displaying in the ng-repeat method. I am unsur ...

Tips for utilizing an IF statement in a Protractorjs Spec.js document?

I am attempting to execute the spec.js file across multiple browsers using Multicapabilities in conf.js. However, I specifically want a certain line of code to only run for Internet Explorer. I have tried putting this code snippet inside an IF statement w ...

Possible reasons for data not appearing on page in AngularJS

Since yesterday, I have been facing an issue with my webpage where the data is not displaying even though everything seems to be configured correctly. Here is the code snippet from the UI that I am using: <html xmlns="http://www.w3.org/1999/xhtml" ng-a ...