Utilizing $mdDialog in a directive linking function with AngularJS Material

I have been attempting to include an Angular Material dialog within a directive's linking function. In theory, it seems like this should work without any issues. According to the documentation, the $mdDialog.show method belongs to a scope and the $mdDialog.hide() is located in a controller defined by the object returned from $mdDialog.show. I managed to make the dialog appear successfully, but even though the closeModal() function gets executed (as evidenced by console logs), unfortunately, $mdDialog.hide() does not execute and the modal remains visible.

angular.module('app', ['ngMaterial'])
    .directive('addLayer', ['$mdDialog', function($mdDialog) {

        return {

            template: '<h1 ng-click="openDialog()">Open Dialog</h1><div>alert: {{alert}}</div>',
            scope: {},
            link: function(scope) {

                scope.alert = '';
                scope.addLayerDialog = function() {

                    $mdDialog.show({

                        parent: angular.element(document.body),
                        templateUrl: {...},
                        controller: function($scope, $mdDialog) {

                            $scope.hide = function() {
                                $mdDialog.hide();

                            };

                            $scope.cancel = function() {

                                $mdDialog.cancel();

                            };

                            $scope.answer = function(answer) {
                                console.log($mdDialog.hide('answer'));
                                $mdDialog.hide(answer);

                            };
                        }

                    }).then(function(answer) {

                        scope.alert = 'You said the information was "' + answer + '".';

                    }, function() {

                        scope.alert = 'You cancelled the dialog.';

                    });

                };

            }

        };
    }]);

What could be causing this issue? Is it perhaps impossible to create an mdDialog modal from within a directive?

Here is the Plnkr I've been experimenting with:

http://plnkr.co/edit/qVczPkuZgtL2CCtLRFrH?p=preview

Thank you for your assistance. This problem has been frustrating me for hours.

Answer №1

Revised: The problem lies in the "transition-in" CSS class - removing it allows for successful hiding of content.

Take a look at the Angular Material git repository; it appears that $mdDialog utilizes the "transition-in" class to display dialogs and "transition-out" to hide them. Including the "transition-in" class will prevent proper hiding of the dialog.

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

Extract information from a webpage using JavaScript through the R programming language

Having just started learning about web scraping in R, I've encountered an issue with websites that utilize javascript. My attempt to scrape data from a specific webpage has been unsuccessful due to the presence of javascript links blocking access to t ...

What is the mechanism behind range traversal in Javascript?

Exploring the createRange() function and related constructs in Javascript has sparked my curiosity about its practical applications. During my search, I stumbled upon an interesting application called "" that allows users to highlight text with mouse clic ...

Validate two schemas with Joi conditionally - Schema content is invalid

I am currently working on implementing a conditional schema based on the value of the isCat field in the request body. However, I keep encountering an error that says 'ror [ERR_ASSERTION]: Invalid schema content'. Any ideas on what might be causi ...

The functionality of Bootstrap tabs is compromised when used within a modal dialog

I am encountering an issue while using Django and Bootstrap to implement nav-tabs within a modal that is displayed upon clicking a button. The problem lies in the fact that when a tab is clicked, its content does not appear. Below is a basic example: {% ...

Including numerous pins on a map

I am currently working on a project that involves extracting data from PHP records to plot markers on a leaflet map using coordinates. Unfortunately, I encountered an error in the console: Error: Invalid LatLng object: (18.473396, undefined) Here is th ...

How can you make the table rows in jQuery scroll automatically while keeping the table header fixed in

Many solutions exist for making the header fixed and the table scrollable using code samples or plugins. However, my specific goal is to have the table data rows scroll automatically once they are loaded while keeping the header fixed in place. Is there a ...

Is it possible to reorganize the JavaScript modules created by the TypeScript compiler?

In my TypeScript project, the structure resembles that of a typical Maven Java project. Here is an overview of how the project is organized: *.js file for commonjs/webpack, system, and amd.</p> For commonjs/webpack, I utilize tsc with tsconfig.jso ...

Efficiently expanding and collapsing multiple levels with Bootstrap through AJAX data responses using jQuery

Looking for help with creating a multi-level expand-collapse feature using JSON data response with jQuery AJAX. As I am new to AJAX, I would appreciate any assistance with implementing the JSON data and expand-collapse plugin. All the data for different l ...

tips for using Node Mailer to send emails without using SMTP

Currently, I am facing an issue with sending emails through nodemailer. Although I have successfully used my gmail account for this purpose in the past, I now wish to switch to using my business email to communicate with clients on a regular basis. The cu ...

Difficulty in displaying modal using jQuery (bootstrap) programmatically

I can't seem to get my bootstrap modal to display manually using my jQuery code <div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="container"> <div ...

transfer a product attribute value to a different product attribute within the Magento platform

There is an attribute called Weight : Attribute Code: weight Scope: general Catalog Input Type for Store Owner: Text Field Values Required: yes Apply To: Simple Product, Bundle Product Allow HTML Tags on Frontend: yes Also, there is a General Weight attr ...

What is the best JavaScript framework for implementing client-side hyphenation?

Looking to improve my website's readability, I want to implement client-side hyphenation using JavaScript for longer texts. Although CSS3 hyphenation is preferred, it's not always available. So far, I've been using Hyphenator.js, which, whi ...

How To Access a View by Clicking in Ionic Framework

I have designed the main screen shown below. When each link is clicked, it should open the corresponding view. https://i.sstatic.net/H84jt.png Here is what I have created so far: Main Screen <body ng-app="starter"> <ion-pane> < ...

Unable to trigger AJAX Complete Handler

Upon completing extensive backend work on my web application, I discovered that the GetMeasure Request was taking up to 10 seconds to finalize. To prevent confusion for potential users, I decided to implement an overlay so that they would not be left stari ...

Leveraging Jquery and an API - restricted

I have the opportunity to utilize a search API that operates on JSON format through a URL GET. This particular API has a reputation for imposing quick bans, with an appeal process that can be lengthy. If I were to integrate this API into my website using ...

Updating the view manually is necessary when using AngularJS $routeProvider and resolve feature

I am facing issues with $routeProvider in updating the view automatically. Currently, I am working on converting a chapter 22 example from Adam Freeman's Pro Angular book, originally based on Deployd, to Express-Mongo. Strangely, the automatic refres ...

What are some ways to improve the precision of longitude and latitude data?

I have encountered an issue while using MapBox. When a user clicks on the map, I am receiving longitude and latitude coordinates that are not very accurate. For example, when I clicked in the United Kingdom, the values pointed me to the middle of the sea a ...

Managing the display of an extensive list of items in react - best practices

I'm facing a challenge with performance as I have a significant number of items to render and the data is constantly being updated in real-time via socket-io. How can I optimize for performance when the table of items is being rendered frequently due ...

Ways to verify if a component triggers an event in VueJS

I am currently working with two components within my application. The Child component emits an 'input' event whenever its value is changed, and the Parent component utilizes v-model to receive this updated value. In order to ensure that the funct ...

In Vue/Javascript, once the user reaches the top of the page, automatically scroll down to reveal an extra navigation bar

My goal is to achieve something similar to what is being done on Snapzu.com: When you reach the top of the window, you can keep scrolling to display different categories. I am looking to implement this functionality using Vue or Javascript, but I haven&ap ...