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