147
147
* @description
148
148
* Emitted every time the ngInclude content is reloaded.
149
149
*/
150
- var ngIncludeDirective = [ '$http' , '$templateCache' , '$anchorScroll' , '$compile' , '$ animate', '$sce' ,
151
- function ( $http , $templateCache , $anchorScroll , $compile , $ animate, $sce ) {
150
+ var ngIncludeDirective = [ '$http' , '$templateCache' , '$anchorScroll' , '$animate' , '$sce' ,
151
+ function ( $http , $templateCache , $anchorScroll , $animate , $sce ) {
152
152
return {
153
153
restrict : 'ECA' ,
154
154
priority : 400 ,
155
155
terminal : true ,
156
156
transclude : 'element' ,
157
+ controller : angular . noop ,
157
158
compile : function ( element , attr ) {
158
159
var srcExp = attr . ngInclude || attr . src ,
159
160
onloadExp = attr . onload || '' ,
@@ -187,22 +188,22 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
187
188
$http . get ( src , { cache : $templateCache } ) . success ( function ( response ) {
188
189
if ( thisChangeId !== changeCounter ) return ;
189
190
var newScope = scope . $new ( ) ;
191
+ ctrl . template = response ;
190
192
191
193
// Note: This will also link all children of ng-include that were contained in the original
192
194
// html. If that content contains controllers, ... they could pollute/change the scope.
193
195
// However, using ng-include on an element with additional content does not make sense...
194
196
// Note: We can't remove them in the cloneAttchFn of $transclude as that
195
197
// function is called before linking the content, which would apply child
196
198
// directives to non existing elements.
197
- var clone = $transclude ( newScope , noop ) ;
198
- cleanupLastIncludeContent ( ) ;
199
+ var clone = $transclude ( newScope , function ( clone ) {
200
+ cleanupLastIncludeContent ( ) ;
201
+ $animate . enter ( clone , null , $element , afterAnimation ) ;
202
+ } ) ;
199
203
200
204
currentScope = newScope ;
201
205
currentElement = clone ;
202
206
203
- currentElement . html ( response ) ;
204
- $animate . enter ( currentElement , null , $element , afterAnimation ) ;
205
- $compile ( currentElement . contents ( ) ) ( currentScope ) ;
206
207
currentScope . $emit ( '$includeContentLoaded' ) ;
207
208
scope . $eval ( onloadExp ) ;
208
209
} ) . error ( function ( ) {
@@ -211,9 +212,28 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
211
212
scope . $emit ( '$includeContentRequested' ) ;
212
213
} else {
213
214
cleanupLastIncludeContent ( ) ;
215
+ ctrl . template = null ;
214
216
}
215
217
} ) ;
216
218
} ;
217
219
}
218
220
} ;
219
221
} ] ;
222
+
223
+ // This directive is called during the $transclude call of the first `ngInclude` directive.
224
+ // It will replace and compile the content of the element with the loaded template.
225
+ // We need this directive so that the element content is already filled when
226
+ // the link function of another directive on the same element as ngInclude
227
+ // is called.
228
+ var ngIncludeFillContentDirective = [ '$compile' ,
229
+ function ( $compile ) {
230
+ return {
231
+ restrict : 'ECA' ,
232
+ priority : - 400 ,
233
+ require : 'ngInclude' ,
234
+ link : function ( scope , $element , $attr , ctrl ) {
235
+ $element . html ( ctrl . template ) ;
236
+ $compile ( $element . contents ( ) ) ( scope ) ;
237
+ }
238
+ } ;
239
+ } ] ;
0 commit comments