A guide on utilizing the onHide feature in angular-strap's modal

I am currently using angular-strap along with the modal service. I am attempting to trigger a function when closing the modal by utilizing the onHide parameter.

var _modal = $modal({
            templateUrl: "app/pages/fee/modals/historic/fee.historic.html",
            controller: "HistoricController",
            controllerAs: "vm",
            keyboard: true,
            show: false,
            onHide: function() {
                console.log("Close !");
            },
            onShow: function() {
                console.log("Open !");
            }
        });
_modal.$promise.then(_modal.show);

However, when I try to close my modal, nothing happens. There are no logs displayed in the console for either opening or closing the modal. I would appreciate any insights or suggestions that anyone may have. Thank you in advance!

Answer №1

Upon further investigation, it appears that the issue is quite amusing.

It seems that when angular-strap is fetched via bower or npm, there is a discrepancy with the $modal. In the locally stored version of angular-strap, even in the latest release 2.3.8, references to onShow or onHide are not present.

  1. Inspecting the source code on the github repository reveals the truth -> https://github.com/mgcrea/angular-strap/blob/master/src/modal/modal.js

Interestingly, onShow and onHide are indeed being triggered in the github repo. This suggests that the modal component is not synchronized with the rest of angular-strap in the distributed versions.

The documentation is not at fault (which was my initial assumption), rather it is the downloaded source that is outdated!

To enable support for onShow, etc., one must merge the latest /modal from the github repo into the local angular-strap. Personally, I opt not to do this as it may lead to complications during upgrades. However, now I understand the reason behind sticking with the original answer.


In my experience, utilizing options like onShow etc. proves to be redundant. Instead, I rely on handlers for the modal.show / modal.hide events, which are always broadcasted. In instances of multiple modals (modals overlaid on each other), assigning tags to the modals can prevent confusion.

var _modal = $modal({
  templateUrl: "app/pages/fee/modals/historic/fee.historic.html",
  controller: "HistoricController",
  controllerAs: "vm",
  keyboard: true,
  show: false,
  tag: 'myModal'
}

$scope.$on('modal.show', function(e, target) {
  if (target.$options.tag == 'myModal') {
    //do stuff here
  }
})
$scope.$on('modal.hide', function(e, target) {
  if (target.$options.tag == 'myModal') {
    //do stuff here
  }
})

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

Steps for obtaining character index upon clicking in HTML:

Is it feasible to determine the character index onClick in relation to the HTML body? I attempted to find a solution, but my efforts were in vain. Unfortunately, I am unable to utilize Jquery because I am working with Angular JS / Ionic. ...

Arranging a group of objects in Angular2

I am facing challenges with organizing an array of objects in Angular2. The structure of the object is as follows: [ { "name": "t10", "ts": 1476778297100, "value": "32.339264", "xid": "DP_049908" }, { "name": "t17", "ts": 14 ...

Twice Asynchronous AJAX Action

Currently, I am working on a javascript script to dynamically load pages on my website without the need to refresh the entire page. The script involves fading out the content div, loading new content, switching the content, and then fading it back in. The ...

I'm curious, who's in charge of determining the height and width in Chrome dev-tools?

There are moments when I feel overwhelmed, struggling to identify the culprit behind certain property values in elements. It can be quite a challenge to pinpoint the source of the issue. Does anyone have any tips for approaching a situation where you arri ...

Guide on adjusting CSS in Vue

Here's the HTML element that I'm working with: <div id="scrollbar" style="background-color: #000;" v-bind:style="{ height : scrollbarheight + 'px' }" ></div> I have been attempting to adj ...

Extend the start day by one day for the checkout option on the Pikaday datepicker

Is there a way to automatically add 1 day to the checkout date when selecting a check-in date? For example, if today is November 8, 2017 and I select November 10 as the check-in date, can the checkout date automatically adjust to November 11? This is the ...

Stop automatic page refresh after submitting a jQuery post request

I've tried various solutions, but unfortunately, neither e.preventDefault() nor return false seem to be working for me. When I use prevent default ajax doesn't make post request. Even using $.post doesn't work as expected. Furthermore, addin ...

Breaking on newline, excluding newline-space in JavaScript

I want to divide my string into an array based on new lines, excluding those that start with a space. ORGANIZER;<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3758455056595e4d524577524f565a475b521954585a">[email prot ...

Obtaining API/JSON Data to Implement in a NextJS Application

Currently, I am working on developing a NextJs website that focuses on detecting crop diseases. The process involves sending photos and environmental data to a fastapi python server for processing. Subsequently, the processed data is supposed to be display ...

Encountering an error when importing chart.js-plugins-annotations

import { annotation, Chart, defaults } from 'chart.js'; An issue arises when using this import statement: localhost/:1 Uncaught TypeError: Failed to resolve module specifier "chart.js". Relative references must start with either &quo ...

What is the process for obtaining the URL of the website that is hosting my iframe?

Do you have a technical inquiry? I am curious to know if it is feasible to retrieve the URL of the website that is hosting my iframe. The pages that host my iframe are utilizing the following code: <iframe id="vacancy-iframe" src="http://mypage.co ...

Encountering an issue when trying to run npm run dev-server on Windows 10

Having trouble running the dev-server for superset-frontend. Encountering this error message. Any assistance would be greatly valued.https://i.stack.imgur.com/zsVU4.png ...

Angular's getter value triggers the ExpressionChangedAfterItHasBeenCheckedError

I'm encountering the ExpressionChangedAfterItHasBeenCheckedError due to my getter function, selectedRows, in my component. public get selectedRows() { if (this.gridApi) { return this.gridApi.getSelectedRows(); } else { return null; } } ...

Is this the correct method for implementing AJAX syntax?

I am currently working on implementing AJAX functionality to verify the existence of a user in my database. At the moment, I am focusing on checking for duplicates based on their first and last name. Below is the code snippet that I have been working on: ...

Issues persist with Jquery draggable not functioning properly, part 2

Trying to implement draggable functionality with jQuery on an element, but encountering issues. Here is the code snippet: <html> <head> <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.cs ...

Unable to execute the query 'DELETE FROM locations ORDER BY id DESC LIMIT 1' in knex.js due to a malfunction

After trying to execute this command: DELETE FROM locations ORDER BY id DESC LIMIT 1 using knex.js, I wrote the following code: knex('locations').delete().orderBy('id', 'desc').limit(1).toString() However, instead of getting ...

How to retrieve only the last value from a JSON object using jQuery's .html

I'm having an issue with jQuery("#someID").html. It seems to only display the last name from the JSON data. Here is the javascript code: <div class="row" id="fetchmember"> <script type="text/javascript"> jQuery('#group').cha ...

Populate an ASP Form using Javascript in Android Studio

Being relatively new to Android studio, I have been experimenting with various methods but now need some assistance. I am looking to input data into an ASP.NET Website-form using Android studio. The traditional JavaScript approach does not seem to be effec ...

Tips for incorporating PHP variables into Javascript code

Working with JavaScript: var counter = 1; var limit = 5; function addInput(divName){ if (counter == limit) { alert("You have reached the limit of adding " + counter + " inputs"); } else { var newdiv = document.createEle ...

The variable ReactFauxDOM has not been declared

Exploring the combination of D3 and React components. Utilizing OliverCaldwell's Faux-DOM element has led me to encounter a frustrating error message stating "ReactFauxDOM is not defined”. Despite following the npm install process correctly... It s ...