Angular $mdDialog allowing for multiple instances to be created

Working with modal tabs, I have a notification pop-up window that is always displayed to the user upon logging into my application. This pop-up contains all events that occurred while the user was offline. The issue arises when clicking on any object from the list, as it closes the pop-up window and opens a new modal tab.

My goal is to achieve a functionality where, upon user login, the notification pop-up window appears and if the user clicks on any object, it opens another window without closing the notification pop-up (showing new events). The desired feature is illustrated in the picture I have attached below.

https://i.sstatic.net/vX44N.jpg

I have consulted the Angular Material documentation, but it lacks a demo and clear explanation of how to work with the multiple: true option to achieve the desired outcome. I am unsure of how to implement it as I want.

https://material.angularjs.org/latest/api/service/$mdDialog

Below is the code for displaying the notification pop-up window:

//show new notifications when user logs in
    NotificationService.getUnreadedNotifications(function (data) {
        //initialization
        $scope.notification = [];
        $scope.OverAllCount = 0;
        $scope.messageNotification = [];
        $scope.OverAllMessageCount = 0;

        if (data.ProjectNotifications != null) {
            angular.forEach(data.ProjectNotifications, function (key, value) {
                $scope.notification.push(key);
                $scope.OverAllCount = $scope.OverAllCount + 1;
            });
        }

        if (data.TasksNotifications != null) {
            angular.forEach(data.TasksNotifications, function (key, value) {
                $scope.notification.push(key);
                $scope.OverAllCount = $scope.OverAllCount + 1;
            });
        }

        if (data.MessageNotifications != null) {
            angular.forEach(data.MessageNotifications, function (key, value) {
                $scope.OverAllMessageCount = $scope.OverAllMessageCount + 1;
                $scope.messageNotification.push(key);
            });
        }

        popUpNotification();

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

        $scope.cancel = function () {
            $mdDialog.cancel();
        };

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

        //mark notifications as read when user clicks on them
        function popUpNotification() {
            $mdDialog.show({
                controller: NotificationController,
                templateUrl: 'app/components/templates/PopUpNotification.html',
                parent: angular.element(document.body),
                clickOutsideToClose: true,
                fullscreen: false,
                scope: $scope,
                multiple:true,
                preserveScope: true,
                onComplete: function () {
                    $scope.notificationPopUp = $scope.notification;
                }
            })
            .then(function () {

            }, function () {
                //fail
            });
        }
    });

And here is the code for displaying details of the object on which the user clicked in a new overlaying modal tab:

//mark notifications as read when user clicks on them
    $scope.popUpDetail = function (notification, index, ev) {
        $mdDialog.show({
            controller: NotificationController,
            templateUrl: 'app/components/templates/TaskDetailsDialog.html',
            parent: angular.element(document.body),
            targetEvent: ev,
            clickOutsideToClose: true,
            fullscreen: false,
            scope: $scope,
            multiple: true,
            preserveScope: true,
            onComplete: function () {
                //update database once notification is read
                NotificationResourceService.update({ id: notification.Id }, notification);
                $scope.OverAllCount -= 1;
                $scope.notification.splice(index, 1);

                TaskService.get({ id: notification.EntityId })
                    .$promise.then(function (task) {
                        $scope.task = task;
                    });
            }
        })
        .then(function () {

        }, function () {
            //fail
        });
    }

Answer №1

After some digging, I managed to find a working solution to my issue. Hopefully, this code snippet will prove useful to someone in the future.

Here is the functional code snippet:

 function showPopUpNotification() {
            $mdDialog.show({
                templateUrl: 'app/components/templates/PopUpNotification.html',
                clickOutsideToClose: true,
                bindToController: true,
                scope: $scope,  
                preserveScope: true,
                controller: function ($scope, $mdDialog) {
                    $scope.notificationPopUp = $scope.notification;
                    $scope.showPopUpDetail = function (notification, index, ev) {
                        $mdDialog.show({
                            controller: function ($mdDialog) {
                                this.close = function () {
                                    $mdDialog.hide();
                                }
                            },
                            targetEvent: ev,
                            clickOutsideToClose: true,
                            preserveScope: true,
                            autoWrap: true,
                            skipHide: true,
                            scope: $scope,
                            preserveScope: true,
                            templateUrl: 'app/components/templates/TaskDetailsDialog.html',
                            onComplete: function () {
                                TaskService.get({ id: notification.EntityId })
                                    .$promise.then(function (task) {
                                        $scope.task = task;
                                    });
                            }
                        })
                    }
                },
                autoWrap: false,
            })
        }
        });

Answer №2

To enable multiple dialogs, simply include the parameter 'multiple: true':

// Using plain options
$mdDialog.show({
  multiple: true
});

// Utilizing a dialog preset
$mdDialog.show(
  $mdDialog
    .alert()
    .multiple(true)
);

For more information, refer to the documentation: https://material.angularjs.org/latest/api/service/$mdDialog

Answer №3

To successfully display the second dialog box without hiding the first one, use the parameter skipHide: true in the object passed to the $mdDialog.show() function. Even without the multiple: true parameter, it will still function correctly. Ensure that the skipHide parameter is included in the object for the second or subsequent dialogs. Your code should resemble the following example:

// Second dialog
$mdDialog.show({
  // Specify some fields
  skipHide: true,
  // Specify other fields
});

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

Using Angular, implementing conditional statements within a for loop

I am currently working on a project where I have an array being looped inside a tag, using the target="_blank" attribute. The issue is that one of the elements in the array should not have this target="_blank" attribute. What would be the best course of ...

Is it necessary to use JS/JQ to trigger PHP form data?

Can PHP files/functions be executed without reloading the page? It can be quite disruptive when developing a chat app and every time you send a message, the entire page refreshes. I attempted to use AJAX but it didn't work. Is it not possible to send ...

Tips on saving a form submit button data to localStorage

As a newcomer, I am on a quest to make this function properly. My goal is to create a form where the submit button saves data to the localStorage. Here's what I have tried thus far. <script> function storeRecipe() { localStorage.setItem($(" ...

Broadcast to every socket except the one that is malfunctioning on Socket.io

My current task involves sending a message to all connected sockets on my server using socket.io. The code I have written so far looks like this: if(electionExists) { var connectedClients = io.sockets.adapter.rooms[electionRequested].sockets; ...

Is there a way to only refresh the div specifically for the calendar with an id of "

$(document).ready(function() { $("#client-list").on("change", function() { var selectedValue = $(this).val(); location.reload(); }); }); Is there a way to refresh only the div with id='calendar' without refreshing the entire pa ...

What is the best way to establish anchors for *ngFor elements in Angular 2 and beyond?

I have a component that displays items using *ngFor. My goal is to scroll down to the element with anchor #3. Here's the code snippet: @Component({ selector: 'my-app', template: ` <button (click)="scroll(3)">scroll 2</butt ...

Sending a large number of values unrestrictedly via ajax

I'm currently working on implementing a filter for the Google Maps API on our website. This filter will allow users to display information related to specific locations that they select by checking corresponding checkboxes. As I am still relatively ne ...

retrieve room from a socket on socket.io

Is there a way to retrieve the rooms associated with a socket in socket.io version 1.4? I attempted to use this.socket.adapter.rooms, but encountered an error in the chrome console: Cannot read property 'rooms' of undefined Here is the method I ...

What is the best way to implement switchMap when dealing with a login form submission?

Is there a better way to prevent multiple submissions of a login form using the switchMap operator? I've attempted to utilize subjects without success. Below is my current code. import { Subject } from 'rxjs'; import { Component, Output } ...

Tips for locating a particular row in Protractor

Can you explain how the solution discussed in this Stack Overflow thread works? I'm interested in understanding the specific logic behind selecting ID0001 in the code snippet provided below: element.all(by.repeater('item in $data track by $index ...

Adding custom fields to the user model in MongoDB using Next Auth during login is not possible

When a user logs in via next auth, I am looking to include custom fields to the default user model. I followed the instructions provided in the official documentation at https://next-auth.js.org/tutorials/typeorm-custom-models. Here is the code snippet: ...

Enhancing a Pie Chart Dynamically with Ajax using Highcharts

I need assistance with updating the data for the pie chart when a list item is clicked. The issue arises when using dynamic values from $cid in data.php. For example, user_student.cid = 1 works correctly, but if I use user_student.cid = $cid, it doesn&apos ...

How can I automatically update the content of a specific Div element when the page is loading using the Ajax load() function

This is the HTML code I have: <body onload="fun1()"> <ul id="nav" class="nav" style="font-size:12px;"> <li><a href="#" id="m_blink" onclick="fun1()">Tab1</a></li> <li><a href="#" id="d_blink" onclick="f ...

Bootstrap 5 dual carousel focus

I have implemented a combo carousel that serves as a timeline slider and displays 14 dates. Along with thumbnails, I am also using dates for navigation. To handle the large number of dates, I need to display them in separate rows, but only show one row at ...

Utilize HTML search input to invoke a JavaScript function

I am currently facing an issue with a navbar form that I have created. The goal is to allow users to input either a 3 digit number or a 5 digit number, which should then trigger a function to open a specific link based on the input. However, I am strugglin ...

How to create a donut chart in Highcharts without an inner pie section?

I've been scouring the internet in search of a solution to create a basic donut chart using the Highcharts library. Most examples I come across show donut charts with both an inner pie and outer donut (see here). Is there a way to remove the inner pi ...

I'm looking to use JavaScript to dynamically generate multiple tabs based on the selected option in a dropdown menu

I'm reaching out with this question because my search for a clear answer or method has come up empty. Here's what I need help with: I've set up a dropdown titled 'Number of Chassis'. Depending on the selection made in this dropdown ...

Firebase scheduled function continues to encounter a persistent issue with an "UNAUTHENTICATED" error being consistently thrown

I have created a firebase-function that is scheduled to retrieve data from an external API source and save it in Firestore. const functions = require("firebase-functions"); const admin = require("firebase-admin"); const { default: Axios ...

The Vue select change event is being triggered prematurely without any user interaction

I am facing an issue with my Vue app where the change event seems to trigger even before I make a selection. I tried using @input instead of @change, but encountered the same problem as described below. I have tested both @change and @input events, but th ...

Can you explain the meaning of arguments[0] and arguments[1] in relation to the executeScript method within the JavascriptExecutor interface in Selenium WebDriver?

When utilizing the executeScript() method from the JavascriptExecutor interface in Selenium WebDriver, what do arguments[0] and arguments[1] signify? Additionally, what is the function of arguments[0] in the following code snippet. javaScriptExecutor.ex ...