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

fix(modal): fix copying from $scope #5048

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,9 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
samePromise = promiseChain = $q.all([promiseChain])
.then(resolveWithTemplate, resolveWithTemplate)
.then(function resolveSuccess(tplAndVars) {
var providedScope = modalOptions.scope || $rootScope;

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

Expand All @@ -641,7 +642,9 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
ctrlInstance = $controller(modalOptions.controller, ctrlLocals);
if (modalOptions.controllerAs) {
if (modalOptions.bindToController) {
angular.extend(ctrlInstance, modalScope);
ctrlInstance.$close = modalScope.$close;
ctrlInstance.$dismiss = modalScope.$dismiss;
angular.extend(ctrlInstance, providedScope);
}

modalScope[modalOptions.controllerAs] = ctrlInstance;
Expand Down
20 changes: 15 additions & 5 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,11 +663,21 @@ describe('$uibModal', function () {
});

it('should allow usage of bindToController', function() {
open({template: '<div>{{test.fromCtrl}} {{test.isModalInstance}}</div>', controller: function($uibModalInstance) {
this.fromCtrl = 'Content from ctrl';
this.isModalInstance = angular.isObject($uibModalInstance) && angular.isFunction($uibModalInstance.close);
}, controllerAs: 'test', bindToController: true});
expect($document).toHaveModalOpenWithContent('Content from ctrl true', 'div');
var $scope = $rootScope.$new(true);
$scope.foo = 'bar';
open({
template: '<div>{{test.fromCtrl}} {{test.closeDismissPresent()}} {{test.foo}}</div>',
controller: function($uibModalInstance) {
this.fromCtrl = 'Content from ctrl';
this.closeDismissPresent = function() {
return angular.isFunction(this.$close) && angular.isFunction(this.$dismiss);
};
},
controllerAs: 'test',
bindToController: true,
scope: $scope
});
expect($document).toHaveModalOpenWithContent('Content from ctrl true bar', 'div');
});
});

Expand Down