AngularJS:关闭模态时的函数调用

时间:2022-12-27 19:38:50

I imagine this is quite a simple answer, but I can't find the right syntax.

我想这是一个非常简单的答案,但我找不到合适的语法。

I have my modal opening like so,

我的模态开口是这样的,

$scope.assignment = function (groupId) {
    var modalInstance = $modal.open({
        templateUrl: 'assignment_form',
        controller: 'GroupsAssignmentController',
        windowClass: 'modal-user-window',
        resolve: {
            id: function () {
                return groupId;
            }
        }
    });

All I want to do is have a function run when the modal is closed so my main screen is updated.

我想要做的就是在模态关闭时运行一个函数,这样我的主屏幕就会更新。

I'm not sure if this involves $modal.close?

我不确定这是否涉及$ modal.close?

    $modal.close({
    //getAllGroups();
    });

1 个解决方案

#1


6  

modalInstance.result.finally(function(){ 
    // do your work here
});

You can also use then

你也可以使用

then(successCallback, errorCallback, notifyCallback) 

SuccessCallback is excetuted when the promise is resolved. errorCallback is executed when the promise is rejected. Finally notifyCallback is executed when notified.

当承诺得到解决时,SuccessCallback超越了。拒绝承诺时执行errorCallback。最后,notifyCallback在收到通知后执行。

In the case of angular-ui's modal, clicking on the backdrop will result in a rejected promise. With this in mind, your code could be changed to :

在angular-ui模态的情况下,单击背景将导致拒绝承诺。考虑到这一点,您的代码可以更改为:

modalInstance.result.then(function () {
  alert('Modal success');
}, function () {
  alert('Modal dismissed');
});

#1


6  

modalInstance.result.finally(function(){ 
    // do your work here
});

You can also use then

你也可以使用

then(successCallback, errorCallback, notifyCallback) 

SuccessCallback is excetuted when the promise is resolved. errorCallback is executed when the promise is rejected. Finally notifyCallback is executed when notified.

当承诺得到解决时,SuccessCallback超越了。拒绝承诺时执行errorCallback。最后,notifyCallback在收到通知后执行。

In the case of angular-ui's modal, clicking on the backdrop will result in a rejected promise. With this in mind, your code could be changed to :

在angular-ui模态的情况下,单击背景将导致拒绝承诺。考虑到这一点,您的代码可以更改为:

modalInstance.result.then(function () {
  alert('Modal success');
}, function () {
  alert('Modal dismissed');
});