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

Commit dd09148

Browse files
committed
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 Closes #5808 Closes #5857
1 parent 5741be9 commit dd09148

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/modal/docs/readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,5 @@ Events fired:
135135
##### UI Router resolves
136136

137137
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).
138+
139+
When the modal is opened with a controller, a `$resolve` object is exposed on the template with the resolved values from the resolve object.

src/modal/modal.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,11 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p
695695
//controllers
696696
if (modalOptions.controller) {
697697
ctrlLocals.$scope = modalScope;
698+
ctrlLocals.$scope.$resolve = {};
698699
ctrlLocals.$uibModalInstance = modalInstance;
699700
angular.forEach(tplAndVars[1], function(value, key) {
700701
ctrlLocals[key] = value;
702+
ctrlLocals.$scope.$resolve[key] = value;
701703
});
702704

703705
// 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
707709
ctrlInstance = ctrlInstantiate.instance;
708710
ctrlInstance.$close = modalScope.$close;
709711
ctrlInstance.$dismiss = modalScope.$dismiss;
710-
angular.extend(ctrlInstance, providedScope);
712+
angular.extend(ctrlInstance, {
713+
$resolve: ctrlLocals.$scope.$resolve
714+
}, providedScope);
711715
}
712716

713717
ctrlInstance = ctrlInstantiate();

src/modal/test/modal.spec.js

+14
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,20 @@ describe('$uibModal', function() {
10531053
});
10541054
expect($document).toHaveModalOpenWithContent('Content from root scope', 'div');
10551055
});
1056+
1057+
it('should expose $resolve in template', function() {
1058+
open({
1059+
controller: function($scope) {},
1060+
resolve: {
1061+
$foo: function() {
1062+
return 'Content from resolve';
1063+
}
1064+
},
1065+
template: '<div>{{$resolve.$foo}}</div>'
1066+
});
1067+
1068+
expect($document).toHaveModalOpenWithContent('Content from resolve', 'div');
1069+
});
10561070
});
10571071

10581072
describe('keyboard', function () {

0 commit comments

Comments
 (0)