Angular UI Bootstrap modal experiencing issues with model binding

Can someone help me with a simple example using Angular UI Bootstrap modal service? I am having trouble with model binding as the expected "Doing something..." message is not displaying on the modal dialog, instead "{{message}}" is shown. What changes do I need to make?

Check out the example here: http://plnkr.co/edit/fJhS3e7At11tJTuNSWAB?p=preview

The modal HTML appears as follows:

<div ng-app="myModule">
    <div ng-controller="modalInstanceController" class="modal-body">
        <div>{{message}}</div>
    </div>
</div>

Below are the module and controller definitions:

var myAppModule = angular.module('myModule', ['ui.bootstrap']);

myAppModule.controller('modalInstanceController', function ($scope, $modalInstance, message) {
    var vm = this;
    vm.message = message;
});

myAppModule.controller('myController', function ($scope, $modal) {


        $scope.open = function open() {

            var modalInstance = $modal.open({
                templateUrl: 'modal.html',
                backdrop: 'static',
                //windowClass: 'custom-modal-wait',
                dialogFade: false,
                keyboard: false,
                controller: 'modalInstanceController',
                resolve: {
                    message: function () {
                        return "Doing something ...";
                    }
                }
            });

            setTimeout(function(){
                modalInstance.close('close');
                },5000);
        }

});

Answer №1

To effectively utilize the data passed to the modal, it must be placed within its scope. Update the modal controller as follows:

myAppModule.controller('modalInstanceController', function ($scope, $modalInstance, message) {
    $scope.message = message;
});

Delete the ng-controller directive from modal.html since the controller is already assigned when the modal instance is created.

ng-controller="modalInstanceController"

Check out the corrected example: http://plnkr.co/edit/RVb80TYN16JktwLzmIXU?p=preview

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

Pop-up confirmation dialog in JQuery following an AJAX request

In order to validate on the server side whether a person with a specific registration number already exists in the database, I have implemented a process. If the person is found registered, the program flow continues as usual. However, if the number is not ...

Altering the background color of a button in a navigation bar and mirroring that same color on a linked page when clicked

I'm facing an issue with my asp.net Master page. I have a menu bar with 4 buttons, and I want to change the color when a button is clicked. I was able to achieve this using java script, but the problem arises when I redirect to a child page, as the co ...

Use the jQuery function `stop(true, true)` to swiftly end all animations currently in the queue

For handling animations in jQuery, I have been utilizing the stop(true, true) method to clear running animations so that the next one can start right away. What I observed was that while the first parameter, clearQueue, clears the entire animation queue, t ...

Submit a form to the same page without reloading and toggle the visibility of a div after submission

Is there a way to submit a form without refreshing the page and hiding the current div while showing a hidden one? I attempted to use the following code, but it ends up submitting the form and reloading the page. <form method="post" name="searchfrm" a ...

What are some strategies for preventing the $window.alert function from being triggered within an AngularJS controller's scope?

How can I prevent the alert from appearing on my dashboard? Do you have any suggestions? Thank you! I attempted to override the alert empty function in my controller, but I am still encountering the window alert when I navigate to my page. $window.alert ...

Subheaders that stay in place while scrolling through a table with a stationary header

My goal is to design a table with a fixed header that allows the body to scroll under the header. While this is a common design, I am facing the challenge of implementing sticky subheaders. These subheaders should scroll along with the table until they rea ...

Trouble displaying selected item in AngularJS dropdown menu

I am dealing with a complex object that looks like this listItems = [ { "id": 1, "name": "myname1" }, { "id": 2, "name": "myname2" }, { "id": 3, "name": "myname3" } ]; My goal is to generate options from the listItems above as shown below &l ...

Enhance your browsing experience with a JavaScript bookmarklet that allows you to easily search through

Struggling to develop a JS Bookmarklet that scans the source code of the current page for a specific code like "G1_Value_client." If found, I need it to trigger alert A; if not found, trigger alert B. Seeking assistance as I am facing some challenges with ...

Can a value be concealed within a dropdown list on a form (using PHP or JavaScript)?

Within my form, there is a drop down box listing the 50 states in the U.S. This list is generated using a PHP for loop. Users are required to select their residential state and later on, they must also choose a mailing state if it differs from their resi ...

Commitments and incorporating items from an array into objects nested within a separate array

My current project involves a command line node application that scrapes valuable data from a specific website and stores it in a CSV file. For the scraping functionality, I am utilizing scrape-it, which enables me to successfully extract all the necessa ...

New Vuetify component for customizing data iterators with specific key names

Can I customize the key names in the Vuetify v-data-iterator component? https://i.sstatic.net/Znv41.jpg I need to change the header names without altering the property names inside the "items" array. How can I achieve this when dealing with special chara ...

Establishing a session variable using express

For my JavaScript project, I want to create a session variable that can be used across all pages. I attempted to use Express for this purpose, but I am facing an issue when trying to assign a value to the session variable. Below is the relevant code snippe ...

The jQuery click event not triggering on ASP.NET control

I am currently developing a C#/Asp application that utilizes jQuery. I am trying to implement a specific function that should be called every time a click event is triggered on an element with a class of "loadingInProgress". However, the code snippet belo ...

Unable to locate the script source. An internal server error 500 has occurred with the node and express-handlebars system

I'm encountering an annoying error 500 because my custom JavaScript scripts are not loading properly. I am currently running a local node.js server with express and express-handlebars. Below is my app.js file: const express = require('express&a ...

Node.js offers a simple and effective way to redirect users to another page after they have

I am experiencing an issue when trying to redirect the client to the confirm page after a successful login process. I keep encountering some errors. view screenshot router.post('/sign_in', urlend, function(req, res) { var email = req.body.user ...

Toggle visibility of a div with bootstrap checkbox - enforce input requirements only if checkbox is marked

Lately, I've been facing a strange issue with using a checkbox that collapses a hidden div by utilizing bootstrap. When I include the attribute data-toggle="collapse" in the checkbox input section, the div collapses but it mandates every single one o ...

On startup of the chrome app, read and load a JSON file into a variable

As I develop a chrome app, my goal is to store all configuration defaults in json file(s) alongside other assets. I am currently using AJAX requests to load them, but I'm wondering if there is a more efficient way to handle this. Is there perhaps an o ...

Leveraging Multiple MongoDB Databases in Meteor.js

Can 2 Meteor.Collections fetch data from separate MongoDB database servers? Dogs = Meteor.Collection('dogs') // mongodb://192.168.1.123:27017/dogs Cats = Meteor.Collection('cats') // mongodb://192.168.1.124:27017/cats ...

What is the best way to display numerous images on a cube face while also organizing them like a gallery wall?

I'm working on creating a unique gallery wall using three.js. Currently, I have successfully rendered an image on each side like this: My goal is to place multiple images on each wall instead of just one large image. Something similar to this concept ...

What is the best way to incorporate a close button into an HTML video popup?

I have a cool feature on my website where an image can be clicked to reveal a popup video that starts playing. However, I would like to know how I can include a close button on the video itself so users can easily return to the website without having to hi ...