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

Commit

Permalink
revert(ngView): remove ngView manual transclusion system
Browse files Browse the repository at this point in the history
  • Loading branch information
matsko authored and mhevery committed Aug 19, 2013
1 parent 6749fef commit b7a5449
Showing 1 changed file with 38 additions and 42 deletions.
80 changes: 38 additions & 42 deletions src/ngRoute/directive/ngView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

ngRouteModule.directive('ngView', ngViewFactory);

/**
* @ngdoc directive
* @name ngRoute.directive:ngView
Expand Down Expand Up @@ -167,22 +169,17 @@
* @description
* Emitted every time the ngView content is reloaded.
*/
var NG_VIEW_PRIORITY = 500;
var ngViewDirective = ['$route', '$anchorScroll', '$compile', '$controller', '$animate',
function($route, $anchorScroll, $compile, $controller, $animate) {
ngViewFactory.$inject = ['$route', '$anchorScroll', '$compile', '$controller', '$animate'];
function ngViewFactory( $route, $anchorScroll, $compile, $controller, $animate) {
return {
restrict: 'ECA',
terminal: true,
priority: NG_VIEW_PRIORITY,
compile: function(element, attr) {
var onloadExp = attr.onload || '';

element.html('');
var anchor = jqLite(document.createComment(' ngView '));
element.replaceWith(anchor);

return function(scope) {
var currentScope, currentElement;
transclude: 'element',
compile: function(element, attr, linker) {
return function(scope, $element, attr) {
var currentScope,
currentElement,
onloadExp = attr.onload || '';

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

if (template) {
cleanupLastView();

currentScope = scope.$new();
currentElement = element.clone();
currentElement.html(template);
$animate.enter(currentElement, null, anchor);

var link = $compile(currentElement, false, NG_VIEW_PRIORITY - 1),
current = $route.current;

if (current.controller) {
locals.$scope = currentScope;
var controller = $controller(current.controller, locals);
if (current.controllerAs) {
currentScope[current.controllerAs] = controller;
var newScope = scope.$new();
linker(newScope, function(clone) {
cleanupLastView();

clone.html(template);
$animate.enter(clone, null, $element);

var link = $compile(clone.contents()),
current = $route.current;

currentScope = current.scope = newScope;
currentElement = clone;

if (current.controller) {
locals.$scope = currentScope;
var controller = $controller(current.controller, locals);
if (current.controllerAs) {
currentScope[current.controllerAs] = controller;
}
clone.data('$ngControllerController', controller);
clone.contents().data('$ngControllerController', controller);

This comment has been minimized.

Copy link
@revolunet

revolunet Nov 15, 2013

Contributor

hi :) can you please explain why there are two controller attributions here ? can't get it

}
currentElement.data('$ngControllerController', controller);
currentElement.children().data('$ngControllerController', controller);
}

current.scope = currentScope;

link(currentScope);
link(currentScope);
currentScope.$emit('$viewContentLoaded');
currentScope.$eval(onloadExp);

currentScope.$emit('$viewContentLoaded');
currentScope.$eval(onloadExp);

// $anchorScroll might listen on event...
$anchorScroll();
// $anchorScroll might listen on event...
$anchorScroll();
});
} else {
cleanupLastView();
}
}
}
}
};
}];

ngRouteModule.directive('ngView', ngViewDirective);
}

0 comments on commit b7a5449

Please sign in to comment.