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

Commit 0b31e86

Browse files
fix(modal): add a work-around for transclusion scope
Fixes #2110 Closes #2134 Closes #2143
1 parent d7c314e commit 0b31e86

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Diff for: src/modal/modal.js

+11
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
110110
};
111111
}])
112112

113+
.directive('modalTransclude', function () {
114+
return {
115+
link: function($scope, $element, $attrs, controller, $transclude) {
116+
$transclude($scope.$parent, function(clone) {
117+
$element.empty();
118+
$element.append(clone);
119+
});
120+
}
121+
};
122+
})
123+
113124
.factory('$modalStack', ['$transition', '$timeout', '$document', '$compile', '$rootScope', '$$stackedMap',
114125
function ($transition, $timeout, $document, $compile, $rootScope, $$stackedMap) {
115126

Diff for: src/modal/test/modalWindow.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ describe('modal window', function () {
99
$compile = _$compile_;
1010
}));
1111

12+
it('should not use transclusion scope for modals content - issue 2110', function () {
13+
$compile('<div modal-window><span ng-init="foo=true"></span></div>')($rootScope);
14+
$rootScope.$digest();
15+
16+
expect($rootScope.foo).toBeTruthy();
17+
});
18+
1219
it('should support custom CSS classes as string', function () {
1320
var windowEl = $compile('<div modal-window window-class="test foo">content</div>')($rootScope);
1421
$rootScope.$digest();

Diff for: template/modal/window.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div tabindex="-1" role="dialog" class="modal fade" ng-class="{in: animate}" ng-style="{'z-index': 1050 + index*10, display: 'block'}" ng-click="close($event)">
2-
<div class="modal-dialog" ng-class="{'modal-sm': size == 'sm', 'modal-lg': size == 'lg'}"><div class="modal-content" ng-transclude></div></div>
2+
<div class="modal-dialog" ng-class="{'modal-sm': size == 'sm', 'modal-lg': size == 'lg'}"><div class="modal-content" modal-transclude></div></div>
33
</div>

0 commit comments

Comments
 (0)