utilizing a modal to trigger a function within the parent scope of an Angular application

I have a main.controller.js where there is a modal in place to notify the user of a warning before proceeding to the rest of the application.

For example, I want to trigger my fileNew function from the modal.

In main.controller.js:

    $scope.warningModal = function() {
                $modal.open({
                  animation: true,
                  templateUrl: "./modal.html",
                  controller: "modalController",
                });
          };
    $scope.fileNew = function(type, subject, application) {
        newApplication(type, subject, application)
          $state.go('submissions');
        });
      };

In main.html:

<li><a ng-click="warningModal()">New app</a></li>

In modal.html:

<div class="modal-body">
  <p>Warning message</p>
</div>
<div class="modal-footer clearfix">
  <button class="pull-right btn btn-primary" ng-click="$parent.fileNew()">Continue</button>
</div>

In modalController:

$scope.$parent.fileNew();

When executing this, an error is shown in the console indicating that $scope.$parent.fileNew is not a function.

Any suggestions on how to resolve this?

EDIT:

Another query related to this concept...

I have three different types of fileNew applications that need to be filed...

In my main controller.js:

$scope.fileNew = function(type, subject, application) {
        newApplication(type, subject, application)
          $state.go('submissions');
        });
      };
$scope.fileOld = function(type, subject, application) {
        newApplication(type, subject, application)
          $state.go('submissions');
        });
      };
$scope.fileEdit = function(type, subject, application) {
        newApplication(type, subject, application)
          $state.go('submissions');
        });
      };

Is it possible to indicate which application type is being clicked on for the same continue button in the modal?

Answer №1

One of the latest features added to Angular UI Bootstrap is the ability to utilize a scope option that allows you to pass a specific scope into your modal controller:

$scope.infoModal = function() {
  $modal.open({
     animation: true,
     scope: $scope,
     templateUrl: "./modal.html",
     controller: "modalController",
  });
};

As a result, you can easily invoke your function from within modalController:

$scope.displayDetails(type, subject, material);

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

In my Express Javascript application, I recently encountered a challenge where I needed to export a const outside of another

I am currently working with a file named signupResponse.js const foundRegisterUser = function(err, foundUser){ if(!err){ console.log("No errors encountered") if(!foundUser){ if(req.body.password == req.body. ...

"AngularJS Service TDD Troubleshooting: How to Overcome

Just starting out with Angular TDD and encountering an error that I can't seem to troubleshoot. Any advice or insights would be greatly appreciated. In my services file: angular.module('myApp') .service('usersLocationService', fu ...

The function does not get activated when mouseover event is triggered with AddEventListener

I am attempting to create a series of radio buttons, each with its own AddEventListener function. However, I am encountering issues while using the code below within a while loop that retrieves data from a MySQLI table: echo ' <script> do ...

Can the Flash Configurator be converted to PHP or Javascript?

Considering converting this flash application into either PHP or JavaScript. Take a look at the example: In PHP, the page reloads every time the customer selects a color. With AJAX, it's challenging to pass the selected value to PHP. Are there any ...

Passport - Pairing Plan "Error|The username provided for sign_request() is not recognized"

Currently experimenting with duo in node.js using passport to test its implementation in an application....Utilizing a passport-duo strategy and encountering issues when trying to apply the example provided in my own project. The GitHub repository for pass ...

Guide to building a dual recursion menu in AngularJS using both functional and template methods

I'm currently working on developing a menu in AngularJS using template and functional recursion. The code I have written involves quite a bit of recursion, so I could really use some assistance. Below is the menu data represented in JSON format: var ...

What is the best way to save a large quantity of objects to a server using ajax and php?

Imagine a scenario where I have a page containing 100 objects, each around 700 bytes when converted to json format. When it comes to saving these objects to the php based controller, there are several options available to me. Option 1: For each object ( ...

Searching for a value in Mongodb using a dynamic key with Node.js

I have been attempting to retrieve a value associated with a key in MongoDB, but so far I have been unsuccessful. Here is an example of my output: { "_id" : { "$oid" : "52cfc91adbffcbe08ccf94b0"} , "customerInfo" : "value"} For instance, if the user inpu ...

Issue with pre-selected checkboxes: JavaScript

A function was created to automatically check the first value of a checkbox when a page is loaded: function defaultCheck(){ document.checkBoxForm.list[0].checked = true; var val=document.checkBoxForm.list[0].value; showtotal[0] = docum ...

Implement Next.js deployment on NGINX server with a 403 forbidden error

I am currently utilizing Next.js for the frontend and Django for the backend. During development, everything is functioning properly. However, when transitioning to production, I am encountering a 403 Forbidden Error related to /_next/static/chunks. It app ...

Tips for confirming a date format within an Angular application

Recently, I've been diving into the world of Angular Validations to ensure pattern matching and field requirements are met in my projects. Despite finding numerous resources online on how to implement this feature, I've encountered some challenge ...

Is there a way to incorporate HTML code into a fullCalendar 4 event title?

Is it possible to add HTML content to an event title using eventRender in FullCalendar version 4? document.addEventListener('DOMContentLoaded', function() { var calendarEl = document.getElementById('calendar'); var calendar = new ...

Having trouble getting the express router to function properly in your Node.js TypeScript project?

One of the components in this application is registerClass, where all routes are added. The source code is in the dist directory since this node app is using TypeScript. However, when calling the http://localhost:9001/user endpoint, it seems that it is not ...

Unusual HTML Structure (content misplaced or out of order?)

Recently, I started learning CSS/HTML in school and we just delved into Javascript. Currently, we are working on a website project. However, while trying to integrate the content with the navbar, I encountered a strange issue. When resizing to 620px or le ...

Ajax versus embedding data directly into the HTML code

Currently, my project involves a combination of JavaScript with jQuery and communication with a Django backend. Some aspects of the user interface require Ajax due to the fact that data to be sent is dependent on user input. On the other hand, there is c ...

Encountered an issue while attempting to send a POST request using AngularJS $

I am facing an issue with accessing the POST method from my server. Whenever I log the response, it always returns status=0. Can anyone help me out or provide some advice? Note: I have tested the method in Postman and it works fine. Below is the code snip ...

guide on launching react with pure javascript

Is it feasible to operate react "straight out of the box" using only JavaScript? In essence, I am seeking a way to utilize react by simply utilizing notepad to create the page (without needing to install and configure node etc.). More specifically - 1) ...

Encountering the error "object object" while attempting to pass parameters to my servlet through AJAX

Experiencing an issue where my ajax call is ending up in the error function. I have noticed that my success function is empty, but I was expecting to receive messages from my servlet whether the data provided is correct or incorrect. The popup dialog displ ...

Socket.io encounters emitting issue within express app.post function

I am working on integrating an express application with a frontend React application using socket connections. My goal is to trigger an event on the connected socket whenever a post request containing JSON data is sent to my server. However, I am facing a ...

What is the method for determining the dimensions of the rectangle that the camera can capture at a specific location?

In my latest project, I developed a small three.js application that showcases the movement of multiple circles from the bottom to the top of the canvas: let renderer, scene, light, circles, camera; initialize(); animate(); function initialize() { re ...