@@ -5124,6 +5124,79 @@ describe('$compile', function() {
5124
5124
} ) ;
5125
5125
5126
5126
5127
+ it ( 'should bind the tranclude function to the original scope when used ' +
5128
+ 'in a future `$compile` call' , function ( ) {
5129
+
5130
+ function countScopes ( $rootScope ) {
5131
+ return [ $rootScope ] . concat (
5132
+ getChildScopes ( $rootScope )
5133
+ ) . length ;
5134
+ }
5135
+
5136
+ function getChildScopes ( scope ) {
5137
+ var children = [ ] ;
5138
+ if ( ! scope . $$childHead ) { return children ; }
5139
+ var childScope = scope . $$childHead ;
5140
+ do {
5141
+ children . push ( childScope ) ;
5142
+ children = children . concat ( getChildScopes ( childScope ) ) ;
5143
+ } while ( ( childScope = childScope . $$nextSibling ) ) ;
5144
+ return children ;
5145
+ }
5146
+
5147
+
5148
+ module ( function ( ) {
5149
+ directive ( 'isolate' , function ( ) {
5150
+ return {
5151
+ scope : { }
5152
+ } ;
5153
+ } ) ;
5154
+ directive ( 'usesTransclude' , function ( $compile ) {
5155
+ return {
5156
+ scope : { foo : '=' } ,
5157
+ transclude : true ,
5158
+ template : '<div><div ng-if="foo"><div ng-transclude></div></div></div>' ,
5159
+ compile : function ( tElement , tAttrs ) {
5160
+ var content = tElement . contents ( ) ;
5161
+ tElement . empty ( ) ;
5162
+ return function ( scope , element , attrs , ctrls , transcludeFn ) {
5163
+ element . append ( content ) ;
5164
+ $compile ( content , transcludeFn ) ( scope ) ;
5165
+ } ;
5166
+ }
5167
+ } ;
5168
+ } ) ;
5169
+ } ) ;
5170
+ inject ( function ( $compile ) {
5171
+ element = $compile (
5172
+ '<div>' +
5173
+ '<div ng-init="outer=true"></div>' +
5174
+ '<div uses-transclude foo="foo">' +
5175
+ '<div uses-transclude foo="foo">' +
5176
+ '<span ng-if="outer">Success</span><span ng-if="!outer">Error</span>' +
5177
+ '</div>' +
5178
+ '</div>' +
5179
+ '</div>' ) ( $rootScope ) ;
5180
+ $rootScope . foo = false ;
5181
+ $rootScope . $digest ( ) ;
5182
+ expect ( countScopes ( $rootScope ) ) . toBe ( 2 ) ;
5183
+ expect ( element . text ( ) ) . toBe ( '' ) ;
5184
+ $rootScope . foo = true ;
5185
+ $rootScope . $digest ( ) ;
5186
+ expect ( countScopes ( $rootScope ) ) . toBe ( 8 ) ;
5187
+ expect ( element . text ( ) ) . toBe ( 'Success' ) ;
5188
+ $rootScope . foo = false ;
5189
+ $rootScope . $digest ( ) ;
5190
+ expect ( countScopes ( $rootScope ) ) . toBe ( 2 ) ;
5191
+ expect ( element . text ( ) ) . toBe ( '' ) ;
5192
+ $rootScope . foo = true ;
5193
+ $rootScope . $digest ( ) ;
5194
+ expect ( countScopes ( $rootScope ) ) . toBe ( 8 ) ;
5195
+ expect ( element . text ( ) ) . toBe ( 'Success' ) ;
5196
+ } ) ;
5197
+ } ) ;
5198
+
5199
+
5127
5200
// see issue https://github.com/angular/angular.js/issues/9095
5128
5201
describe ( 'removing a transcluded element' , function ( ) {
5129
5202
0 commit comments