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

Commit

Permalink
feat(modal): expose $close and $dismiss options on modal's scope
Browse files Browse the repository at this point in the history
Closes #966
  • Loading branch information
pkozlowski-opensource committed Sep 8, 2013
1 parent 0caea91 commit 8d153ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/modal/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ The `open` method returns a modal instance, an object with the following propert
* `close(result)` - a method that can be used to close a modal, passing a result
* `dismiss(reason)` - a method that can be used to dismiss a modal, passing a reason
* `result` - a promise that is resolved when a modal is closed and rejected when a modal is dismissed
* `opened` - a promise that is resolved when a modal gets opened after downloading content's template and resolving all variables
* `opened` - a promise that is resolved when a modal gets opened after downloading content's template and resolving all variables

In addition the scope associated with modal's content is augmented with 2 methods:
* `$close(result)`
* `$dismiss(reason)`
Those methods make it easy to close a modal window without a need to create a dedicated controller
6 changes: 4 additions & 2 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ angular.module('ui.bootstrap.modal', [])
result: modalResultDeferred.promise,
opened: modalOpenedDeferred.promise,
close: function (result) {
$modalStack.close(this, result);
$modalStack.close(modalInstance, result);
},
dismiss: function (reason) {
$modalStack.dismiss(this, reason);
$modalStack.dismiss(modalInstance, reason);
}
};

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

var modalScope = (modalOptions.scope || $rootScope).$new();
modalScope.$close = modalInstance.close;
modalScope.$dismiss = modalInstance.dismiss;

var ctrlInstance, ctrlLocals = {};
var resolveIter = 1;
Expand Down

0 comments on commit 8d153ac

Please sign in to comment.