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

Commit b7a5449

Browse files
matskomhevery
authored andcommitted
revert(ngView): remove ngView manual transclusion system
1 parent 6749fef commit b7a5449

File tree

1 file changed

+38
-42
lines changed

1 file changed

+38
-42
lines changed

src/ngRoute/directive/ngView.js

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

3+
ngRouteModule.directive('ngView', ngViewFactory);
4+
35
/**
46
* @ngdoc directive
57
* @name ngRoute.directive:ngView
@@ -167,22 +169,17 @@
167169
* @description
168170
* Emitted every time the ngView content is reloaded.
169171
*/
170-
var NG_VIEW_PRIORITY = 500;
171-
var ngViewDirective = ['$route', '$anchorScroll', '$compile', '$controller', '$animate',
172-
function($route, $anchorScroll, $compile, $controller, $animate) {
172+
ngViewFactory.$inject = ['$route', '$anchorScroll', '$compile', '$controller', '$animate'];
173+
function ngViewFactory( $route, $anchorScroll, $compile, $controller, $animate) {
173174
return {
174175
restrict: 'ECA',
175176
terminal: true,
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;
177+
transclude: 'element',
178+
compile: function(element, attr, linker) {
179+
return function(scope, $element, attr) {
180+
var currentScope,
181+
currentElement,
182+
onloadExp = attr.onload || '';
186183

187184
scope.$on('$routeChangeSuccess', update);
188185
update();
@@ -203,42 +200,41 @@ var ngViewDirective = ['$route', '$anchorScroll', '$compile', '$controller', '$a
203200
template = locals && locals.$template;
204201

205202
if (template) {
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;
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);
221224
}
222-
currentElement.data('$ngControllerController', controller);
223-
currentElement.children().data('$ngControllerController', controller);
224-
}
225-
226-
current.scope = currentScope;
227225

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

230-
currentScope.$emit('$viewContentLoaded');
231-
currentScope.$eval(onloadExp);
232-
233-
// $anchorScroll might listen on event...
234-
$anchorScroll();
230+
// $anchorScroll might listen on event...
231+
$anchorScroll();
232+
});
235233
} else {
236234
cleanupLastView();
237235
}
238236
}
239237
}
240238
}
241239
};
242-
}];
243-
244-
ngRouteModule.directive('ngView', ngViewDirective);
240+
}

0 commit comments

Comments
 (0)