1
1
'use strict' ;
2
2
3
- ngRouteModule . directive ( 'ngView' , ngViewFactory ) ;
4
-
5
3
/**
6
4
* @ngdoc directive
7
5
* @name ngRoute.directive:ngView
@@ -169,17 +167,22 @@ ngRouteModule.directive('ngView', ngViewFactory);
169
167
* @description
170
168
* Emitted every time the ngView content is reloaded.
171
169
*/
172
- ngViewFactory . $inject = [ '$route' , '$anchorScroll' , '$compile' , '$controller' , '$animate' ] ;
173
- function ngViewFactory ( $route , $anchorScroll , $compile , $controller , $animate ) {
170
+ var NG_VIEW_PRIORITY = 500 ;
171
+ var ngViewDirective = [ '$route' , '$anchorScroll' , '$compile' , '$controller' , '$animate' ,
172
+ function ( $route , $anchorScroll , $compile , $controller , $animate ) {
174
173
return {
175
174
restrict : 'ECA' ,
176
175
terminal : true ,
177
- transclude : 'element' ,
178
- compile : function ( element , attr , linker ) {
179
- return function ( scope , $element , attr ) {
180
- var currentScope ,
181
- currentElement ,
182
- onloadExp = attr . onload || '' ;
176
+ priority : NG_VIEW_PRIORITY ,
177
+ compile : function ( element , attr ) {
178
+ var onloadExp = attr . onload || '' ;
179
+
180
+ element . html ( '' ) ;
181
+ var anchor = jqLite ( document . createComment ( ' ngView ' ) ) ;
182
+ element . replaceWith ( anchor ) ;
183
+
184
+ return function ( scope ) {
185
+ var currentScope , currentElement ;
183
186
184
187
scope . $on ( '$routeChangeSuccess' , update ) ;
185
188
update ( ) ;
@@ -200,41 +203,42 @@ function ngViewFactory( $route, $anchorScroll, $compile, $controller,
200
203
template = locals && locals . $template ;
201
204
202
205
if ( template ) {
203
- var newScope = scope . $new ( ) ;
204
- linker ( newScope , function ( clone ) {
205
- cleanupLastView ( ) ;
206
-
207
- clone . html ( template ) ;
208
- $animate . enter ( clone , null , $element ) ;
209
-
210
- var link = $compile ( clone . contents ( ) ) ,
211
- current = $route . current ;
212
-
213
- currentScope = current . scope = newScope ;
214
- currentElement = clone ;
215
-
216
- if ( current . controller ) {
217
- locals . $scope = currentScope ;
218
- var controller = $controller ( current . controller , locals ) ;
219
- if ( current . controllerAs ) {
220
- currentScope [ current . controllerAs ] = controller ;
221
- }
222
- clone . data ( '$ngControllerController' , controller ) ;
223
- clone . contents ( ) . data ( '$ngControllerController' , controller ) ;
206
+ cleanupLastView ( ) ;
207
+
208
+ currentScope = scope . $new ( ) ;
209
+ currentElement = element . clone ( ) ;
210
+ currentElement . html ( template ) ;
211
+ $animate . enter ( currentElement , null , anchor ) ;
212
+
213
+ var link = $compile ( currentElement , false , NG_VIEW_PRIORITY - 1 ) ,
214
+ current = $route . current ;
215
+
216
+ if ( current . controller ) {
217
+ locals . $scope = currentScope ;
218
+ var controller = $controller ( current . controller , locals ) ;
219
+ if ( current . controllerAs ) {
220
+ currentScope [ current . controllerAs ] = controller ;
224
221
}
222
+ currentElement . data ( '$ngControllerController' , controller ) ;
223
+ currentElement . children ( ) . data ( '$ngControllerController' , controller ) ;
224
+ }
225
+
226
+ current . scope = currentScope ;
225
227
226
- link ( currentScope ) ;
227
- currentScope . $emit ( '$viewContentLoaded' ) ;
228
- currentScope . $eval ( onloadExp ) ;
228
+ link ( currentScope ) ;
229
229
230
- // $anchorScroll might listen on event...
231
- $anchorScroll ( ) ;
232
- } ) ;
230
+ currentScope . $emit ( '$viewContentLoaded' ) ;
231
+ currentScope . $eval ( onloadExp ) ;
232
+
233
+ // $anchorScroll might listen on event...
234
+ $anchorScroll ( ) ;
233
235
} else {
234
236
cleanupLastView ( ) ;
235
237
}
236
238
}
237
239
}
238
240
}
239
241
} ;
240
- }
242
+ } ] ;
243
+
244
+ ngRouteModule . directive ( 'ngView' , ngViewDirective ) ;
0 commit comments