Using AngularJS to pass data through UI modal

Here we have a ui-select element that allows users to choose from various options:

<ui-select ng-model="state.selected" ng-change="openModal(state.selected,orders.order_id)" ng-if="orders.state == 'Paid'" theme="selectize" ng-disabled="disabled" style="width: 300px;"> .....

Whenever there are changes, a modal from bootstrap is triggered.

$scope.openModal = function(name,oid){
    $scope.modalInstance = $modal.open({
        templateUrl: 'reservationModal.html',
        scope:$scope,
        name: function(){
            return name;
        }
    });
}

$scope.cancel = function(){
    $scope.modalInstance.dismiss();
}

$scope.confirmChg = function(){
    console.log('ok...');
}

The template used is as shown below:

<script type="text/ng-template" id="reservationModal.html">
    <div class="modal-header">
        <h3 class="modal-title">Confirmation</h3>
        <!--<button class="btn btn-warning" ng-click="close()">X</button>-->
    </div>
    <div class="modal-body">
        Confirm to change status to {{name}} ?

    </div>
    <div class="modal-footer">
        <button class="btn btn-danger" type="button" ng-click="confirmChg(status_oid,status)">Yes</button>
        <button class="btn btn-warning" type="button" ng-click="cancel()" data-dismiss="modal">No</button>
    </div>
</script>

The issue faced here is that the {{name}} variable in the template does not display. What can be done to successfully pass this variable from the open modal function?

Answer №1

Make sure to assign the name to the scope by including this line:

$scope.name = name;

This should be done before invoking $scope.open. Therefore, your openModal function will appear as follows:

$scope.openModal = function(name,oid){
    $scope.name = name;
    $scope.modalInstance = $modal.open({
        templateUrl: 'reservationModal.html',
        scope:$scope,
        name: function(){
            return name;
        }
    });
}

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

What is the best way to transform the selected days of the week into comma-separated integers using JavaScript?

Users can select checkboxes for each day of the week. Below is an example JS object: {"mon":true,"tue":true,"wed":true,"thu":false,"fri":false,"sat":false,"sun":false} The goal is to convert these selections into a string of comma-separated values, with ...

Draggable and Droppable: initiate a drop at a specific location after a designated period

Code Snippet: $( ".tile" ).draggable({ helper: "clone", start:function ( event, ui){ setTimeout(function(){ removePlaceholder(); performAction(); },1000); }, stop:function( event, ui ) { performAction(); } }); My Goal: A ...

Guide to creating a toggle button

Can someone help me create a button that toggles between displaying block and display none when clicked? I've been trying to use Classlist.toggle with JavaScript, but I'm not sure if I have the correct classes targeted. let showCart = documen ...

Understanding how to use Vuejs Components across multiple DOM elements, as well as how to initialize a Vue instance and utilize the "el

Imagine transitioning from the jQuery realm. If you are working with a component myPlugin (jQuery plug-in, such as a tool that displays tooltips when hovering over specific DOM elements) it would be initialized like this: $('.tooltipClass').myP ...

Sequelize is having trouble recognizing a valid moment.js object within the where clause

In my Sequelize query, I am facing an issue with the createdAt property in the where object: let prms = periods.map((period, index, arr) => { if (arr[index + 1]) { return sequelize.models.Result.aggregate('value', 'avg', ...

Animating an element when another one fades away

const myVueInstance = new Vue({ el: '#app', data: { showBlueElement: true } }) .a, .b { height: 50px; width: 50px; background: red; } .b { background: blue; transition: transform 1s ease-in-out; } <script src="https://unpk ...

Exploring ways to display a JavaScript object on click from a .json file

As I delve into the world of javascript and json, I find myself facing a challenge. I am looking to extract information (using the Get Information function) from a json file within a javascript function triggered by an event. The catch is, I want to accom ...

Comparing JSON and JavaScript object arrays: Exploring the differences in outcomes and strategies for achieving desired results

Although it's not valid JSON, I've found that by declaring this as a variable directly in my code, I can treat it like an object. <script> // this will result in object var mydata = { users: [{ person: { ...

Retrieving user input value from AngularJS

Currently, I am utilizing AngularJS to handle form submission and then transfer the value to my Laravel function. Below is the HTML code: <form class="form-horizontal" method="post" name='form' novalidate ng-submit="submit()" ng-controller=" ...

Transfer an object for reusability in a different JavaScript file without utilizing the default operator

I have a scenario where I have two files organized in a tree structure that defines an object. The first file is called common.js. export default { table: { actions: { save: 'Save', delete: 'Delete', update: ...

How can you identify if JavaScript is turned off without relying on the noscript tag?

While working on designing a pop-up notification for cases when JavaScript is disabled, I incorporated html, css, and bootstrap elements into my project. An issue arose as I pondered if there exists a method to identify whether the html class within my p ...

AngularJS: Issue with placeholder not being displayed

I'm having an issue with my code where only one of two img elements is being displayed simultaneously. The scope for both imgs is defined in the controller, but for some reason, only one shows up in the default context. Here is the complete source cod ...

Efficiently managing and saving properties across User Controls

Currently, I am working on an ASP.NET application that utilizes a collection of UserControls. Within this application, there is a page that displays various custom UserControls. One of these controls, known as ucA, includes a small JavaScript Popup that r ...

What could be causing wavesurferjs to exceed the boundaries of its parent div?

I need assistance with my wavesurferjs issue The waveform is overflowing the parent div This problem occurs for the first time and upon resize of the parent div Upon resizing, it should automatically adjust to fit the parent div Question: When the pare ...

Unable to utilize the useState hook in TypeScript (Error: 'useState' is not recognized)

Can you identify the issue with the following code? I am receiving a warning from TypeScript when using useState import * as React, { useState } from 'react' const useForm = (callback: any | undefined) => { const [inputs, setInputs] = useS ...

Experiencing CORS (Cross-Origin Resource Sharing) issue while utilizing Python Flask-Restful in conjunction with consuming AngularJS (specifically with $

Currently, I am using a Python program in conjunction with the flask-restful extension to provide a restful service. My goal is to consume this service with an AngularJS app. So far, everything is functioning properly on my localhost. However, whenever I m ...

Guide to setting up a universal state modification controller using ui-router

I'm in the process of developing my first angular application and have organized many of the main features into separate modules. Each module defines its routes in the config using $stateProvider. One challenge I am facing is how to efficiently handl ...

Determine the length of the current line in a text area with JQuery

Is there a way in JQuery to easily validate the current line of a Text Area when the user presses the enter key? Specifically, I want it to return false if the current line length is 0, and true otherwise. ...

Pair participants within a game search array

I've been contemplating this issue extensively but I'm struggling to come up with a fast and efficient solution using JavaScript. I have an array of objects representing game searches for random players. The array might resemble the following: co ...

Why is the setTimeout() function called for the 2nd member of the object but not for the 1st member?

In the code example I'm sharing in this question, there's a 3D array (basically a JS object) named outerArray. This array consists of inner arrays (technically objects) that each contain multiple url objects. Each url object has a url field and a ...