149
149
* @description
150
150
* Emitted every time the ngInclude content is reloaded.
151
151
*/
152
- var NG_INCLUDE_PRIORITY = 500 ;
153
152
var ngIncludeDirective = [ '$http' , '$templateCache' , '$anchorScroll' , '$compile' , '$animate' , '$sce' ,
154
153
function ( $http , $templateCache , $anchorScroll , $compile , $animate , $sce ) {
155
154
return {
156
155
restrict : 'ECA' ,
157
156
terminal : true ,
158
- priority : NG_INCLUDE_PRIORITY ,
159
- compile : function ( element , attr ) {
157
+ transclude : 'element' ,
158
+ compile : function ( element , attr , transclusion ) {
160
159
var srcExp = attr . ngInclude || attr . src ,
161
160
onloadExp = attr . onload || '' ,
162
161
autoScrollExp = attr . autoscroll ;
163
162
164
- element . html ( '' ) ;
165
- var anchor = jqLite ( document . createComment ( ' ngInclude: ' + srcExp + ' ' ) ) ;
166
- element . replaceWith ( anchor ) ;
167
-
168
- return function ( scope ) {
163
+ return function ( scope , $element ) {
169
164
var changeCounter = 0 ,
170
165
currentScope ,
171
166
currentElement ;
@@ -189,21 +184,23 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
189
184
if ( thisChangeId !== changeCounter ) return ;
190
185
var newScope = scope . $new ( ) ;
191
186
192
- cleanupLastIncludeContent ( ) ;
187
+ transclusion ( newScope , function ( clone ) {
188
+ cleanupLastIncludeContent ( ) ;
193
189
194
- currentScope = newScope ;
195
- currentElement = element . clone ( ) ;
196
- currentElement . html ( response ) ;
197
- $animate . enter ( currentElement , null , anchor ) ;
190
+ currentScope = newScope ;
191
+ currentElement = clone ;
198
192
199
- $compile ( currentElement , false , NG_INCLUDE_PRIORITY - 1 ) ( currentScope ) ;
193
+ currentElement . html ( response ) ;
194
+ $animate . enter ( currentElement , null , $element ) ;
195
+ $compile ( currentElement . contents ( ) ) ( currentScope ) ;
200
196
201
- if ( isDefined ( autoScrollExp ) && ( ! autoScrollExp || scope . $eval ( autoScrollExp ) ) ) {
202
- $anchorScroll ( ) ;
203
- }
197
+ if ( isDefined ( autoScrollExp ) && ( ! autoScrollExp || scope . $eval ( autoScrollExp ) ) ) {
198
+ $anchorScroll ( ) ;
199
+ }
204
200
205
- currentScope . $emit ( '$includeContentLoaded' ) ;
206
- scope . $eval ( onloadExp ) ;
201
+ currentScope . $emit ( '$includeContentLoaded' ) ;
202
+ scope . $eval ( onloadExp ) ;
203
+ } ) ;
207
204
} ) . error ( function ( ) {
208
205
if ( thisChangeId === changeCounter ) cleanupLastIncludeContent ( ) ;
209
206
} ) ;
0 commit comments