Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why pass a parameter to $uibModalInstance.close(parameter)?

When calling $uibModalInstance.close(parameter) I understand that it closes the current modal window.

But what does the parameter inside the close() method do?

like image 401
Abhijit Chakra Avatar asked Nov 28 '25 13:11

Abhijit Chakra


1 Answers

When you open a modal it will return an object with several promises, one of those promises is result, this promise will be resolved when you call close with the parameter given to it.

var modalInstance = $uibModal.open({
    controller: function($uibModalInstance) {
        $uibModalInstance.close('testParameter');
    }
});

modalInstance.result.then(function(parameter) {
    console.log(parameter); // logs 'testParameter'
});

A common pattern is to have a save/confirm button in your modal, and handling the result in the result success. To cancel the action (reject the result promise) you can call $uibModalinstance.dismiss(reason)

like image 159
Martijn Welker Avatar answered Nov 30 '25 04:11

Martijn Welker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!