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

Commit 8adfc83

Browse files
committed
feat(modal): add support for bindToController
- Add `bindToController` support in modal options Closes #3965 Resolves #3404
1 parent a861a2c commit 8adfc83

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/modal/docs/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The `$modal` service has only one method: `open(options)` where available option
88
* `scope` - a scope instance to be used for the modal's content (actually the `$modal` service is going to create a child scope of a provided scope). Defaults to `$rootScope`
99
* `controller` - a controller for a modal instance - it can initialize scope used by modal. Accepts the "controller-as" syntax in the form 'SomeCtrl as myctrl'; can be injected with `$modalInstance`
1010
* `controllerAs` - an alternative to the controller-as syntax, matching the API of directive definitions. Requires the `controller` option to be provided as well
11+
* `bindToController` - when used with `controllerAs` & set to `true`, it will bind the controller properties onto the `$scope` directly
1112
* `resolve` - members that will be resolved and passed to the controller as locals; it is equivalent of the `resolve` property for AngularJS routes
1213
* `animation` - set to false to disable animations on new modal/backdrop. Does not toggle animations for modals/backdrops that are already displayed.
1314
* `backdrop` - controls presence of a backdrop. Allowed values: true (default), false (no backdrop), `'static'` - backdrop is present but modal window is not closed when clicking outside of the modal window.

src/modal/modal.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,11 @@ angular.module('ui.bootstrap.modal', [])
464464

465465
ctrlInstance = $controller(modalOptions.controller, ctrlLocals);
466466
if (modalOptions.controllerAs) {
467-
modalScope[modalOptions.controllerAs] = ctrlInstance;
467+
if (modalOptions.bindToController) {
468+
angular.extend(modalScope, ctrlInstance);
469+
} else {
470+
modalScope[modalOptions.controllerAs] = ctrlInstance;
471+
}
468472
}
469473
}
470474

src/modal/test/modal.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,14 @@ describe('$modal', function () {
440440
}, controllerAs: 'test'});
441441
expect($document).toHaveModalOpenWithContent('Content from ctrl true', 'div');
442442
});
443+
444+
it('should allow usage of bindToController', function () {
445+
open({template: '<div>{{fromCtrl}} {{isModalInstance}}</div>', controller: function($modalInstance) {
446+
this.fromCtrl = 'Content from ctrl';
447+
this.isModalInstance = angular.isObject($modalInstance) && angular.isFunction($modalInstance.close);
448+
}, controllerAs: 'test', bindToController: true});
449+
expect($document).toHaveModalOpenWithContent('Content from ctrl true', 'div');
450+
});
443451
});
444452

445453
describe('resolve', function () {

0 commit comments

Comments
 (0)