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

Commit 8d153ac

Browse files
feat(modal): expose $close and $dismiss options on modal's scope
Closes #966
1 parent 0caea91 commit 8d153ac

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/modal/docs/readme.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ The `open` method returns a modal instance, an object with the following propert
1616
* `close(result)` - a method that can be used to close a modal, passing a result
1717
* `dismiss(reason)` - a method that can be used to dismiss a modal, passing a reason
1818
* `result` - a promise that is resolved when a modal is closed and rejected when a modal is dismissed
19-
* `opened` - a promise that is resolved when a modal gets opened after downloading content's template and resolving all variables
19+
* `opened` - a promise that is resolved when a modal gets opened after downloading content's template and resolving all variables
20+
21+
In addition the scope associated with modal's content is augmented with 2 methods:
22+
* `$close(result)`
23+
* `$dismiss(reason)`
24+
Those methods make it easy to close a modal window without a need to create a dedicated controller

src/modal/modal.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,10 @@ angular.module('ui.bootstrap.modal', [])
247247
result: modalResultDeferred.promise,
248248
opened: modalOpenedDeferred.promise,
249249
close: function (result) {
250-
$modalStack.close(this, result);
250+
$modalStack.close(modalInstance, result);
251251
},
252252
dismiss: function (reason) {
253-
$modalStack.dismiss(this, reason);
253+
$modalStack.dismiss(modalInstance, reason);
254254
}
255255
};
256256

@@ -270,6 +270,8 @@ angular.module('ui.bootstrap.modal', [])
270270
templateAndResolvePromise.then(function resolveSuccess(tplAndVars) {
271271

272272
var modalScope = (modalOptions.scope || $rootScope).$new();
273+
modalScope.$close = modalInstance.close;
274+
modalScope.$dismiss = modalInstance.dismiss;
273275

274276
var ctrlInstance, ctrlLocals = {};
275277
var resolveIter = 1;

0 commit comments

Comments
 (0)