Retrieve information from a pop-up modal and showcase it in a table within the main controller

How can we transfer data from a modal to a main controller table and update the table on clicking the generate button in the modal? Currently, I am able to retrieve input text data from the generate button click event but the table is not being updated with this data. Access my code on Plunker: https://plnkr.co/edit/yk4Zcl6LF79cw4msYUrw?p=preview


// AngularJS code

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

myTable.controller('tableCtrl', function($scope, $http, $uibModal) {

    $scope.Catalogs = [];   
    $scope.phNumber = [];
    $scope.schema=[{"value":"2.0"},{"value":"2.2"}];
    $scope.revision=[{"value":"ARev"},{"value":"XRev"}];

    $http({
        method: 'GET',
        url: 'http://100.96.16.175:8080/CGSDataManager/webapi/component_type',
        headers: {'Accept': 'application/json'}
    }).success(function(data) {
        $scope.components = data;
    });

    $http({
        method: 'GET',
        url: 'http://100.96.16.175:8080/CGSDataManager/webapi/platform_info',
        headers: {'Accept': 'application/json'}
    }).success(function(data) {
        $scope.systems = data
        for(var i = 0; i < data.length; i++) {
            $scope.phNumber = data[i].platform_id;
        }
    });

    $scope.change = function() {
        // Modal configuration
        
        var modalInstance = $uibModal.open({
            templateUrl: 'modalView1.html',
            controller: 'ModalInstanceCtrl',
            resolve: { item: function() {
                return angular.copy({schema: $scope.schema, revision: $scope.revision, components: $scope.components, systems: $scope.systems, phNumber: $scope.phNumber, Catalogs: $scope.Catalogs});
            }}
        });

        modalInstance.result.then(function(){
            // On OK button press
        }, function(){
            // On cancel button press
            console.log("Modal Closed");
        });
    };  

});

myTable.controller('ModalInstanceCtrl', function ($scope, $uibModalInstance, item) {
    $scope.item = item;

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

    $scope.submitData = function() {
        $scope.item.Catalogs.push({name: $scope.catalogName, validation: "true", publishing: "hello"});
        $uibModalInstance.dismiss('submit');
    };
});
// HTML and CSS code can be found in the Plunker link provided.

Answer №1

For more information, please visit this link

Remember to include this code snippet when closing the modal and accessing it in the controller:

  $uibModalInstance.dismiss($scope.item.Catalogs);

Answer №2

Utilize $rootScope to store data globally

myTable.controller('tableCtrl', function($scope, $rootScope,$http, $uibModal) {
    $rootScope.Catalogs = [];   
})

In a different controller, add data to the global Catalogs array, not to item.catalogs

myTable.controller('ModalInstanceCtrl', function ($scope,$rootScope, $uibModalInstance, item) {
$scope.submitData = function() {


        $rootScope.Catalogs.push({name: $scope.catalogName,validation: "true", publishing: "hello"});

}
});

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

Analyzing and adding Angular JSON information

I'm struggling to understand why the compare function and insert function in my code aren't functioning correctly. I suspect that one reason for this could be that the function is not being called by the button. How can I confirm this? It seems l ...

Transform the text column into JSON format

We currently have a resource bundle/properties formatted as follows: [tag1] server1 server2 [tag2] server3 server4 [tag3] server5 server6 [No Software Installed] server7 [tag2] server8 [tag5] server9 [tag1] server10 server11 [tag3] server12 server13 serve ...

Is there a way to trigger a modal popup when hovering over a Bootstrap 5 card?

After coming across a handy template online, I decided to implement a modal pop-up feature when hovering over cards using Bootstrap 5. Here's what I have so far: class SavedEpisodes extends Component { $(function() { $('[data-toggle=&qu ...

organize a data set using react's hook system

Trying to sort an array using react hooks but the state is not updating. Any help on what could be going wrong? import React, { useState } from "react"; import ReactDOM from "react-dom"; import "./styles.css"; const dogs = [{ name: "fido", age: 22 }, ...

Generating an MD5 hash for a UTF16LE string in Javascript (with no BOM and excluding 0-byte at the end) - Illustrated with a C#

I've been trying to figure out how to get an MD5 Hash of a UTF16-LE encoded string in JavaScript for the past few days. I have a method in C# as an example, but I'm not sure how to replicate it in JavaScript. Example: public string GetMD5Hash ( ...

What is the best approach to validate null Date in an AngularJS application using ng-if directive?

How can I use ng-if in AngularJS to check for null Date? The HTML Source Code: <!DOCTYPE html> <html> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <body> <div ng-app="myApp" ...

Implement a loading bar on the entire page in Vue.js while a request is being made

There is an "edit" button on my page which allows me to edit certain elements and either save or close without saving. I would like to implement a loading bar that displays when the user clicks the "save" button, indicating that the data is being processe ...

Adding a navigation bar to every administrator page while excluding it from shop pages can be achieved by creating a

I am facing a challenge in implementing a navbar and sidebar on all admin pages, except for the shop page. The issue arises because I have set my sidebar and navbar to be global. My goal is to make them global only for admin pages and not for the shop. He ...

Text area in the footer of a Bootstrap-4 modal that can be scrolled through

In my Angular-6 project, I am implementing a Bootstrap-4 modal. The Modal-Header has a fixed height, Modal-Body is scrollable, and Modal-Footer has a variable height but is not scrollable. Below is a snippet of my basic HTML: /*for debugging purpose*/ ...

Is there a specific HTML tag available to instruct the browser to cache my HTML and/or CSS files for future use?

Up to this point, my research has indicated that enabling JavaScript and CSS browser caching typically requires server side settings such as .htaccess. Is there any HTML tag or configuration within the HTML page or JavaScript that can instruct the browse ...

The functionality of Quickblox is currently experiencing issues when used with subdomain URLs

I have several URLs for the same domain, but they contain subdomains like the following: admin.projectname.com doctor.projectname.com etc.. The Quickblox API call is not functioning properly with these URLs and is displaying the following error message: ...

Struggling to generate fresh vue components

Having trouble registering new components in my Vue app. I have successfully registered some components, but when I try to register a new one, I encounter the error: Unknown custom element: <store> - did you register the component correctly? For re ...

Exploring the retrieval of JavaScript array elements from a ListModel within QML

Currently, I have some JavaScript data that consists of a list of objects containing other objects and arrays, which I want to append to a ListModel. This is what the structure looks like (assuming that the data is generated elsewhere and its structure sh ...

Guide on extracting data from a specific column in an object and converting it into a list using JavaScript

Imagine we are working with the following JSON information var example = [{ latitude: 11.1111, longitude: 111.111, name: "for example1", altitude: 88 }, { latitude: 22.2222, longitude: 222.222, name: "for example2 ...

Ways to ensure that the height of the second row in the second column matches that of the first column

My current layout design is causing an issue where the lower green box extends beyond the total height of the entire box. I've provided a rough version of my code on codepen. Using the Bulma framework, my goal is to align the height of the left column ...

Implementing Multiple HTML Files Loading in QUnit

Currently, I am utilizing QUnit for unit testing JavaScript and jQuery. The structure of my HTML document is as follows: <!DOCTYPE html> <html> <head> <title>QUnit Test Suite</title> <script src="../lib/jquery.js">< ...

Ways to transition between divs using clickable buttons

I have a coding challenge where I need to implement two panels. The lower panel consists of three buttons and upon clicking each button, different data should load in the upper panel. For example, when button 1 is clicked, divs 1.1, 1.2, and 1.3 should sl ...

How to effectively inject moment.js dependency into AngularJS?

In my app.js file, I've defined my app module like this: var myApp = angular.module('myApp', ['angularMoment']); Next, in my controller, I'm trying to use the moment() function: myApp.controller('myComtroller', [& ...

Step-by-step guide on incorporating a hyperlink within a row using @material-ui/data-grid

I am currently using @material-ui/data-grid to showcase some data on my webpage. Each row in the grid must have a link that leads to the next page when clicked. I have all the necessary data ready to be passed, however, I am facing difficulty in creating a ...

How come the function is being triggered by my onclick button as soon as the page loads?

Currently, I am experiencing a challenge in my NodeJS project with Express. The issue lies with my EJS client side file when it comes to handling button click events. In my EJS file, I have imported a function from a JS file and can invoke it using <% ...