Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 87405e2

Browse files
matskomhevery
authored andcommitted
fix(ngView): ensure ngView is terminal and uses its own manual transclusion system
1 parent 1b5bee4 commit 87405e2

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed

src/ngRoute/directive/ngView.js

+42-38
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
ngRouteModule.directive('ngView', ngViewFactory);
4-
53
/**
64
* @ngdoc directive
75
* @name ngRoute.directive:ngView
@@ -169,17 +167,22 @@ ngRouteModule.directive('ngView', ngViewFactory);
169167
* @description
170168
* Emitted every time the ngView content is reloaded.
171169
*/
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) {
174173
return {
175174
restrict: 'ECA',
176175
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;
183186

184187
scope.$on('$routeChangeSuccess', update);
185188
update();
@@ -200,41 +203,42 @@ function ngViewFactory( $route, $anchorScroll, $compile, $controller,
200203
template = locals && locals.$template;
201204

202205
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;
224221
}
222+
currentElement.data('$ngControllerController', controller);
223+
currentElement.children().data('$ngControllerController', controller);
224+
}
225+
226+
current.scope = currentScope;
225227

226-
link(currentScope);
227-
currentScope.$emit('$viewContentLoaded');
228-
currentScope.$eval(onloadExp);
228+
link(currentScope);
229229

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();
233235
} else {
234236
cleanupLastView();
235237
}
236238
}
237239
}
238240
}
239241
};
240-
}
242+
}];
243+
244+
ngRouteModule.directive('ngView', ngViewDirective);

0 commit comments

Comments
 (0)