Weirdly enough, Angular's $uibModalInstance.close() function doesn't seem to actually close the modal

In my project, I have a modal that prompts the user to enter some input. The logic of the code is structured as follows:

When the user clicks on the 'Add' button, a modal window appears asking for input. After entering the input, the user clicks 'okay'.

On the controller side, the following code snippet shows the functionality:

$scope.ok = function() {

   if (entered_value == 'disk') {
      //perform some actions
      $uibModalInstance.close(); //this closes the modal
   }

   else {
      // perform some actions
      $uibModalInstance.close();
   }
}

Under normal conditions, this code works fine - executing different actions based on user input ('disk' or anything else).

However, a problem arises when repeatedly clicking 'okay' and entering user values. For example:

  • First click on 'Add', enter 'data' as input, and the modal closes.
  • Second click on 'Add', enter 'asa' as input, but the modal does not close because $uibModalInstance.close() was already executed previously.

To address this issue and ensure the modal closes each time, any advice or suggestions would be greatly appreciated. Thank you!

Answer №1

Here is a suggestion to try:

$modalInstanceCtrl = $uibModalInstance;
$ctrl.okay = function() {

if (input_value == 'disk') {
   // carry out specific actions
   $modalInstanceCtrl.close(); //closes the modal window
}

else {
   // perform other actions
   $modalInstanceCtrl.close();

}

}

By implementing this code, you can access it within the current 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

Searching through an array of objects that contain nested child objects

I am currently trying to find a way to search through an Array that has nested Objects in order to find a specific value and then retrieve the object in which it is found to store it in a new array. This is the code snippet I am working with: var json = ...

The Bootstrap modal fails to open

I am currently working on implementing a Navbar button that triggers a Bootstrap modal containing a form. While looking for resources, I stumbled upon a useful script at https://gist.github.com/havvg/3226804. I'm in the process of customizing it to su ...

Postman sends requests by utilizing AJAX and adhering to the same origin policy

I recently came across a Chrome extension called Postman that has proven to be incredibly useful. This tool is particularly handy for those working with RESTful applications. One thing that has puzzled me is how Postman is able to successfully send POST r ...

Anomalies encountered during the iteration of a table

As I work on building a table by looping through an API array, I've encountered a few obstacles. Here is the code snippet that's causing me trouble -> $html = " <tr class='mt-2'> <td>{$rank}.</td> ...

Deleting all JSON files in a directory using NodeJs

Is there a way to delete only the json files within a directory (multiple levels) without specifying each file name individually? I thought fs-unlinkSync(path) might work, but I haven't found that solution yet. I attempted to use the following method ...

I must determine whether the contents of an array exceed zero

THE SUMMARY: I have three value numbers for an array. If the total addition of the array's elements is greater than 0, I need to display "el funcionamiento no es infinito", otherwise "es infinito". It seems that it's not working because I belie ...

Troubleshooting Firefox's inability to properly utilize jQuery's scrollTop() function on the 'body' element

I'm puzzled as to why the scrollTop() jquery function isn't functioning properly on the 'body' element in Firefox. $('body').scrollTop(0); To resolve this issue, I ended up using: $(window).scrollTop(0); The jquery documen ...

Navigating a Dynamic entity using a button in AFrame

I've inquired about this topic previously, but I feel my question wasn't clear. My goal is to construct a plinko-style aframe world with a ball that resets to its starting position when clicked. While I prefer to use a button to reset the ball, c ...

Is the relevance of Angular 1.x still prevalent in today's development landscape

Considering I have several projects in angular 1.x, I'm contemplating whether it's truly essential and efficient to upgrade them to angular 4 or a later version. The smaller dashboards do not necessarily require an update since they are only use ...

creating dynamic data objects in ajax calls

https://jsfiddle.net/c7n34e3x/1/ from data, data1, and data2, only data is functioning, but it lacks dynamism. This method works as intended. var settings = { "async": true, "crossDomain": true, "url": "https://domain/api/v2/playlists/", ...

Is it possible to dynamically change HTML content by utilizing a JSON file?

Looking to implement a JavaScript loop (using jQuery) that can dynamically populate the HTML file with content from a JSON file based on matching <div> ids to the JSON "id" values. The solution should be scalable and able to handle any number of < ...

Transformation from a graphql query to a json query

In exploring the GraphQL example, I am wondering how to make a similar request with JSON in Javascript. The GraphQL query in the example is: { trip( from: {place: "NSR:StopPlace:5533" }, to: {place:"NSR:StopPlace:5532"} ) { tripPatte ...

How to center elements in a card and list group using Bootstrap 4

As a newbie to Bootstrap and coding, I'm seeking guidance on how to center all the list items below, including the card title. Despite researching on Stackoverflow, I couldn't successfully implement it. <link rel="stylesheet" href="https:// ...

Enhance your AngularJS skills by incorporating multiple conditions into the ternary operations of ng-class

I am struggling to apply multiple classes when the condition in the ng-class attribute evaluates to true. Here is the code I have attempted so far, but it doesn't seem to be working: <div class="col-md-4" ng-mouseover="hoverButton=true" id="plai ...

Set up AngularJS application to save API URLs

In configuring my API endpoint and URL's, I utilize a custom app.config.js file with environment variables: angular.module('api-config', []).constant('ENV', { name: 'My Project Name', apiEndPoint: 'http://SO ...

Retrieving Values from Array Objects - Using JavaScript

Discovering the technique to retrieve property values. Given the following: let object1 = [{name: "HappyHands31"}, {job: "website developer"}, {city: "Chicago"}]; How can I output only the value of the second object, which is "website developer"? I am ...

From AngularJS, switch your dots to commas for a fresh

As a beginner in angularjs, I am facing an issue with my program which reads prices from a .json file. The prices are all in decimal format with dots instead of commas. I am looking for guidance on creating a directive or another solution to replace the do ...

Harness the power of our custom directive when integrating with x-editable functionality

Is it possible to apply a custom directive to an editable-text element? <span ui-Blur="testfn(price);" editable-text="entry.product_id" e-name="product_id" e-style="width: 200px" e-form="sentryform" e-required> </span> ...

Obtain the Ajax function to provide a result of either true or false

I'm struggling to make an Ajax function return a true or false value for validation purposes. The other function needs to receive this value to determine the next steps. I'm certain I've accomplished this before, but for some reason, it&apo ...

Angular UI.Bootstrap Carousel: Identifying the Current Slide's Index

Is there a way to synchronize the movement of an angular bootstrap directive carousel with an animation of another image? For example, when the carousel switches to show the 5th slide, I need to display the corresponding 5th image from an array. I assume ...