From b38c4f44357ab6b25ea19dab44116eb66fe75ba1 Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Thu, 28 Apr 2016 16:37:44 -0700 Subject: [PATCH] feat(modal): add resolve values to template - Expose resolve in template as $resolve for those modals opened with a controller BREAKING CHANGE: Since this adds support for $resolve being exposed on $scope, it could potentially overwrite any pre-existing usage of it - this is an unlikely scenario, but marked as a breaking change in case this key is being used --- src/modal/docs/readme.md | 2 ++ src/modal/modal.js | 6 +++++- src/modal/test/modal.spec.js | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/modal/docs/readme.md b/src/modal/docs/readme.md index 0e6e838271..50f3fc9105 100644 --- a/src/modal/docs/readme.md +++ b/src/modal/docs/readme.md @@ -135,3 +135,5 @@ Events fired: ##### UI Router resolves If one wants to have the modal resolve using [UI Router's](https://github.com/angular-ui/ui-router) pre-1.0 resolve mechanism, one can call `$uibResolve.setResolver('$resolve')` in the configuration phase of the application. One can also provide a custom resolver as well, as long as the signature conforms to UI Router's [$resolve](http://angular-ui.github.io/ui-router/site/#/api/ui.router.util.$resolve). + +When the modal is opened with a controller, a `$resolve` object is exposed on the template with the resolved values from the resolve object. diff --git a/src/modal/modal.js b/src/modal/modal.js index 804e208dd3..356299da8b 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -695,9 +695,11 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p //controllers if (modalOptions.controller) { ctrlLocals.$scope = modalScope; + ctrlLocals.$scope.$resolve = {}; ctrlLocals.$uibModalInstance = modalInstance; angular.forEach(tplAndVars[1], function(value, key) { ctrlLocals[key] = value; + ctrlLocals.$scope.$resolve[key] = value; }); // the third param will make the controller instantiate later,private api @@ -707,7 +709,9 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p ctrlInstance = ctrlInstantiate.instance; ctrlInstance.$close = modalScope.$close; ctrlInstance.$dismiss = modalScope.$dismiss; - angular.extend(ctrlInstance, providedScope); + angular.extend(ctrlInstance, { + $resolve: ctrlLocals.$scope.$resolve + }, providedScope); } ctrlInstance = ctrlInstantiate(); diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index 8de6c8497a..1e43b037d2 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -1053,6 +1053,20 @@ describe('$uibModal', function() { }); expect($document).toHaveModalOpenWithContent('Content from root scope', 'div'); }); + + it('should expose $resolve in template', function() { + open({ + controller: function($scope) {}, + resolve: { + $foo: function() { + return 'Content from resolve'; + } + }, + template: '
{{$resolve.$foo}}
' + }); + + expect($document).toHaveModalOpenWithContent('Content from resolve', 'div'); + }); }); describe('keyboard', function () {