Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.
This repository was archived by the owner on May 29, 2019. It is now read-only.

[$modal] - ability to distinguish modals (by ids) and close a particular modal #3019

@DmitryEfimenko

Description

@DmitryEfimenko

I have a case when a message might come to the website via sockets and based on that message I need to close a particular modal (not all opened modals) if it's open.

For this I propose to add an optional parameter id to the modal:

var modalInstance = {
    id: modalOptions.id,
    result: modalResultDeferred.promise,
    opened: modalOpenedDeferred.promise,
    close: function (result) {
        $modalStack.close(modalInstance, result);
    },
    dismiss: function (reason) {
        $modalStack.dismiss(modalInstance, reason);
    }
};

and add two more methods to $modalStack:

$modalStack.getAll = function () {
    return openedWindows.keys();
};

$modalStack.closeById = function(id, result) {
    var modalInstance = null;
    var opened = $modalStack.getAll();
    for (var i = 0, l = opened.length; i < l; i++) {
        if (opened[i].id == id) {
            modalInstance = openedWindows.get(opened[i]);
            break;
        } 
    }
    if (modalInstance) {
        $modalStack.close(modalInstance.key, result);
    }
}

This way developer will be able to achieve this functionality with ease.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions