Issue: Bidirectional binding functionality is not functioning properly within the user interface modal

I'm currently working on displaying data in a modal, but I'm facing issues with getting two-way binding to work properly.

In my HTML code:

<div class="cta-actions">
  <div class="action"><a class="btn btn-lg btn-max">Send a package</a></div>
  <div class="action"><a id="estimate-modal-trigger" ng-click="openPriceEstimateModal()" class="btn btn-lg">Get an estimate</a></div>
</div>

In the controller:

$scope.openPriceEstimateModal = function() {
        var modalInstance = $uibModal.open({
          animation: true,
          templateUrl: '/app/tpls/partials/estimate.modal.html',
          windowClass: 'price-estimate-modal',
          controller: 'EstimateModalCtrl'
       });
    };

For the modal's controller:

controller('EstimateModalCtrl', function($scope, $timeout, $uibModalInstance) {
  $scope.btnText = "Estimate"
  $scope.data = {
    pickup_address: null,
    delivery_address: null,
    cost: 0
  };

  $scope.address = {}
});

Here is the modal template (in jade format):

.modal-header
.modal-body
  .estimate-price-display
     h1
       span.currency &#8358;
       span.value(ng-bind="data.cost")

  .estimate-form
    form(name="form" no-validate)
      .control-group
        label Pickup Address
        input.form-control(pac type="text" name="pickup" placeholder="Enter pickup address" ng-model="data.pickup_address" ng-required="true" details="address.pickup")

      .control-group
        label Delivery Address
        input.form-control(pac type="text" name="delivery" placeholder="Enter delivery address" ng-model="data.delivery_address" ng-required="data.pickup_address" details="address.delivery")

      .control-group(style="text-align: center;")
        .button.btn.btn-lg.btn-clr-white(type="button" ng-click="getEstimate()" ng-disabled="form.$invalid" ng-bind="btnText")

Although the properties bind correctly and are displayed in the modal, changing the value of $scope.btnText or $scope.data.cost does not update in the modal template. However, checking the $scope object in the console shows that the changes have been applied. Is there something incorrect in my approach?

Answer №1

One way to ensure the $scope is passed to the Modal instance is by following these steps:

$scope.openPriceEstimateModal = function() {
     var modalInstance = $uibModal.open({
          animation: true,
          scope : $scope,
          templateUrl: '/app/tpls/partials/estimate.modal.html',
          windowClass: 'price-estimate-modal',
          controller: 'EstimateModalCtrl'
      });
};

Normally, the default scope passed to the modal instance is $rootScope, but in this case, you need to override that with $scope.

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

Avoiding the storage of POST data in JSON format

Here is some code I am working with: var jsonString = "some string of json"; $.post('proxy.php', { data : jsonString }, function(response) { var print = response; alert(print); }); And this P ...

In a React app, there are instances where `localstorage.getitem('key')` may result in returning null

I've encountered a strange issue while building a login form that sets a JWT token in localstorage. The problem arises when, despite being able to see the token in my console.log, setting localstorage.getitem('idToken') sometimes returns nul ...

The functionality of Jquery is successfully integrated into a specific function, however it seems to only work for one of the calls. To make the other call work,

After a user makes a selection, I am attempting to reset the 'selected' item. This process calls the Vue function tS() shown below. The issue lies with the first call $('#sel1').prop('selectedIndex',0);, as it only seems to wo ...

Steps to achieve a fully expanded sidenav using Angular Material

Currently, I am utilizing Angular-Material and have successfully integrated a SideNav menu into my project. However, there is an issue with the menu’s appearance based on screen size. When the screen is small, the menu remains hidden until the Menu toggl ...

A peaceful WCF service initiates a client callback whenever a server update occurs

In the process of developing a WCF RESTFUL service on top of a c++ console application, I am confronted with an issue. The client accesses this c++ application through my restful wcf service using a browser. Every time there is an update received by my w ...

Sort Ionic Expandable List

Currently, I am in the process of creating an application using Ionic framework. One feature in my app involves displaying a list with professions and their corresponding specialties in an accordion format, as demonstrated below: Profession 1 Specialty ...

What is the best way to enhance an object using a class in ES6?

In an effort to improve the clarity of my ES6 class definition, my current code looks like this: class SomeClass { constructor({a, b, c, d, e}) { this.a = a; this.b = b; this.c = c; this.d = d; this.e = e; // additional code here ...

executing jQuery toggle on freshly generated content

I have a webpage that I designed using jQuery. Within this page, there is a table with rows assigned specific color classnames (e.g., tr class="yellowclass"). Users can filter the rows by clicking checkboxes to show/hide tables of different colors. The i ...

Is it advisable to load 10,000 rows into memory within my Angular application?

Currently, I am in the process of creating a customer management tool using Angular.js that will allow me to directly load 10,000 customers into the $scope. This enables me to efficiently search for specific data and manipulate it without the need for serv ...

There seems to be a malfunction in the editing feature of AngularJS

Why am I receiving values in a text box instead of a span when adding data? Additionally, why is the "Done" button showing up instead of the "Update" button after adding data? See my full code here: https://jsfiddle.net/GowthamG/jL5oza04/. Is there an er ...

Adjust a Javascript script to choose the best font color for use in R Shiny applications

I am currently seeking to determine the font color of hover messages based on the background color. This means white if the background is dark, and black if it is light. However, I stumbled upon a Stack Overflow question with a Javascript solution that see ...

Searching through a JSON object for nested objects within objects

Currently, I have some data structured as follows: var items = [ { "id" : 1, "title" : "this", "groups" : [ {"id" : 1, "name" : "groupA"}, {"id" : 2, "name" : "groupB"} ] }, { "id" : 2, "title" : "that", ...

How to style the background color of the selected option in a <select> element using

Is there a specific style I can use to change the color of a selected option in a dropdown menu? For example: <HTML> <BODY> <FORM NAME="form1"> <SELECT NAME="mySelect" SIZE="7" style="background-color:red;"> <OPTION>Test 1 &l ...

Free up MySQL connections within a Promise.All implementation

At the moment, I am facing issues with releasing MySQL connections from a connection pool. Interestingly, when I release connections in a synchronous "for" loop, everything works fine. However, when I attempt to release them asynchronously using Promise.Al ...

I created a thorough duplicate that successfully addressed an issue with a table

Currently, I am facing an issue with the material-table library as it automatically adds a new element called tableData to my object when I update it using Patch in my code and API. To resolve this problem, I tried implementing both a conventional and cust ...

Tips on passing methods to form provider with unique name for managing nested forms

As discussed in #60277873, when creating nested forms, it is necessary to rename the methods of the nested form as follows: const { register, formState: { errors }, handleSubmit, } = useForm({ mode: "onBlur", }); This code sh ...

An effective approach to positioning HTML elements at specific X and Y coordinates

I have an innovative project idea! The concept is to enable users to create points by clicking on the display. They can then connect these points by clicking again. However, I am facing a challenge when it comes to creating HTML elements at the exact loc ...

"Convert a date string to a date object using the verbose moment date

I utilized the materialize datepicker to select a date in French format. Now I need to convert this formatted date back to a date object for use in my API. Here's how I attempted to revert the date to a standard format: moment("dimanche 30 juillet 20 ...

ASP.NET DIV is experiencing issues with Jquery functionality, causing it to flicker and remain fixed in place

As a beginner in JQuery, I am facing an issue with my code in asp.net. Whenever I click on linkbuttons, the behavior is not as expected. The div flickers and does not change its direction. My goal is to move the DIV left or right by 200px, but no matter wh ...

Is it possible to customize the color of icons in react's Material-table?

I'm currently utilizing the material-table library and I'm struggling to individually change the color of each icon. Could you assist me with this? I attempted custom CSS, but it's affecting all icons at once instead of specific ones. Here i ...