From 46e215ef93f357c550fd55171d3b54b52563953a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Sat, 17 Aug 2013 11:39:28 -0400 Subject: [PATCH 1/2] revert(ngInclude): remove ngInclude manual transclusion system --- src/ng/directive/ngInclude.js | 35 ++++++++++++++---------------- test/ng/directive/ngIncludeSpec.js | 25 --------------------- 2 files changed, 16 insertions(+), 44 deletions(-) diff --git a/src/ng/directive/ngInclude.js b/src/ng/directive/ngInclude.js index e4484e819162..0f1f245c2bc1 100644 --- a/src/ng/directive/ngInclude.js +++ b/src/ng/directive/ngInclude.js @@ -149,23 +149,18 @@ * @description * Emitted every time the ngInclude content is reloaded. */ -var NG_INCLUDE_PRIORITY = 500; var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile', '$animate', '$sce', function($http, $templateCache, $anchorScroll, $compile, $animate, $sce) { return { restrict: 'ECA', terminal: true, - priority: NG_INCLUDE_PRIORITY, - compile: function(element, attr) { + transclude: 'element', + compile: function(element, attr, transclusion) { var srcExp = attr.ngInclude || attr.src, onloadExp = attr.onload || '', autoScrollExp = attr.autoscroll; - element.html(''); - var anchor = jqLite(document.createComment(' ngInclude: ' + srcExp + ' ')); - element.replaceWith(anchor); - - return function(scope) { + return function(scope, $element) { var changeCounter = 0, currentScope, currentElement; @@ -189,21 +184,23 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile' if (thisChangeId !== changeCounter) return; var newScope = scope.$new(); - cleanupLastIncludeContent(); + transclusion(newScope, function(clone) { + cleanupLastIncludeContent(); - currentScope = newScope; - currentElement = element.clone(); - currentElement.html(response); - $animate.enter(currentElement, null, anchor); + currentScope = newScope; + currentElement = clone; - $compile(currentElement, false, NG_INCLUDE_PRIORITY - 1)(currentScope); + currentElement.html(response); + $animate.enter(currentElement, null, $element); + $compile(currentElement.contents())(currentScope); - if (isDefined(autoScrollExp) && (!autoScrollExp || scope.$eval(autoScrollExp))) { - $anchorScroll(); - } + if (isDefined(autoScrollExp) && (!autoScrollExp || scope.$eval(autoScrollExp))) { + $anchorScroll(); + } - currentScope.$emit('$includeContentLoaded'); - scope.$eval(onloadExp); + currentScope.$emit('$includeContentLoaded'); + scope.$eval(onloadExp); + }); }).error(function() { if (thisChangeId === changeCounter) cleanupLastIncludeContent(); }); diff --git a/test/ng/directive/ngIncludeSpec.js b/test/ng/directive/ngIncludeSpec.js index b712c130f207..f1bfbba21c7c 100644 --- a/test/ng/directive/ngIncludeSpec.js +++ b/test/ng/directive/ngIncludeSpec.js @@ -280,31 +280,6 @@ describe('ngInclude', function() { dealoc(element); })); - it('should compile only the inner content once', function() { - var log = []; - - module(function($compileProvider) { - $compileProvider.directive('compileLog', function() { - return { - compile: function() { - log.push('compile'); - } - }; - }); - }); - - inject(function($compile, $rootScope, $templateCache) { - $templateCache.put('tpl.html', [200, '
123
', {}]); - element = $compile('
')($rootScope); - - $rootScope.exp = 'tpl.html'; - $rootScope.$digest(); - - expect(element.text()).toBe('123'); - expect(log).toEqual(['compile']); - }); - }); - describe('autoscoll', function() { var autoScrollSpy; From d8363c19790a01327eb2a871b644fefd93c5fd64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Sat, 17 Aug 2013 11:48:48 -0400 Subject: [PATCH 2/2] revert(ngView): remove ngView manual transclusion system --- src/ngRoute/directive/ngView.js | 80 ++++++++++++++++----------------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/src/ngRoute/directive/ngView.js b/src/ngRoute/directive/ngView.js index 44232231a497..6a1f2012117e 100644 --- a/src/ngRoute/directive/ngView.js +++ b/src/ngRoute/directive/ngView.js @@ -1,5 +1,7 @@ 'use strict'; +ngRouteModule.directive('ngView', ngViewFactory); + /** * @ngdoc directive * @name ngRoute.directive:ngView @@ -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(); @@ -203,35 +200,36 @@ 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); } - 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(); } @@ -239,6 +237,4 @@ var ngViewDirective = ['$route', '$anchorScroll', '$compile', '$controller', '$a } } }; -}]; - -ngRouteModule.directive('ngView', ngViewDirective); +}