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

Commit 811bf96

Browse files
committed
fix(modal): fix bindToController implementation
- Correct the implementation of `bindToController` to match Angular with properties on `$scope` being bound on the controller Closes #4054 Fixes #4051
1 parent 277b30c commit 811bf96

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/modal/docs/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +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
11+
* `bindToController` - when used with `controllerAs` & set to `true`, it will bind the $scope properties onto the controller directly
1212
* `resolve` - members that will be resolved and passed to the controller as locals; it is equivalent of the `resolve` property for AngularJS routes
1313
* `animation` - set to false to disable animations on new modal/backdrop. Does not toggle animations for modals/backdrops that are already displayed.
1414
* `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

+3-3
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,10 @@ angular.module('ui.bootstrap.modal', [])
538538
ctrlInstance = $controller(modalOptions.controller, ctrlLocals);
539539
if (modalOptions.controllerAs) {
540540
if (modalOptions.bindToController) {
541-
angular.extend(modalScope, ctrlInstance);
542-
} else {
543-
modalScope[modalOptions.controllerAs] = ctrlInstance;
541+
angular.extend(ctrlInstance, modalScope);
544542
}
543+
544+
modalScope[modalOptions.controllerAs] = ctrlInstance;
545545
}
546546
}
547547

src/modal/test/modal.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ describe('$modal', function () {
480480
});
481481

482482
it('should allow usage of bindToController', function () {
483-
open({template: '<div>{{fromCtrl}} {{isModalInstance}}</div>', controller: function($modalInstance) {
483+
open({template: '<div>{{test.fromCtrl}} {{test.isModalInstance}}</div>', controller: function($modalInstance) {
484484
this.fromCtrl = 'Content from ctrl';
485485
this.isModalInstance = angular.isObject($modalInstance) && angular.isFunction($modalInstance.close);
486486
}, controllerAs: 'test', bindToController: true});

0 commit comments

Comments
 (0)