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

Commit 6749fef

Browse files
matskomhevery
authored andcommitted
revert(ngInclude): remove ngInclude manual transclusion system
1 parent 63e9ea1 commit 6749fef

File tree

2 files changed

+16
-44
lines changed

2 files changed

+16
-44
lines changed

src/ng/directive/ngInclude.js

+16-19
Original file line numberDiff line numberDiff line change
@@ -149,23 +149,18 @@
149149
* @description
150150
* Emitted every time the ngInclude content is reloaded.
151151
*/
152-
var NG_INCLUDE_PRIORITY = 500;
153152
var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile', '$animate', '$sce',
154153
function($http, $templateCache, $anchorScroll, $compile, $animate, $sce) {
155154
return {
156155
restrict: 'ECA',
157156
terminal: true,
158-
priority: NG_INCLUDE_PRIORITY,
159-
compile: function(element, attr) {
157+
transclude: 'element',
158+
compile: function(element, attr, transclusion) {
160159
var srcExp = attr.ngInclude || attr.src,
161160
onloadExp = attr.onload || '',
162161
autoScrollExp = attr.autoscroll;
163162

164-
element.html('');
165-
var anchor = jqLite(document.createComment(' ngInclude: ' + srcExp + ' '));
166-
element.replaceWith(anchor);
167-
168-
return function(scope) {
163+
return function(scope, $element) {
169164
var changeCounter = 0,
170165
currentScope,
171166
currentElement;
@@ -189,21 +184,23 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
189184
if (thisChangeId !== changeCounter) return;
190185
var newScope = scope.$new();
191186

192-
cleanupLastIncludeContent();
187+
transclusion(newScope, function(clone) {
188+
cleanupLastIncludeContent();
193189

194-
currentScope = newScope;
195-
currentElement = element.clone();
196-
currentElement.html(response);
197-
$animate.enter(currentElement, null, anchor);
190+
currentScope = newScope;
191+
currentElement = clone;
198192

199-
$compile(currentElement, false, NG_INCLUDE_PRIORITY - 1)(currentScope);
193+
currentElement.html(response);
194+
$animate.enter(currentElement, null, $element);
195+
$compile(currentElement.contents())(currentScope);
200196

201-
if (isDefined(autoScrollExp) && (!autoScrollExp || scope.$eval(autoScrollExp))) {
202-
$anchorScroll();
203-
}
197+
if (isDefined(autoScrollExp) && (!autoScrollExp || scope.$eval(autoScrollExp))) {
198+
$anchorScroll();
199+
}
204200

205-
currentScope.$emit('$includeContentLoaded');
206-
scope.$eval(onloadExp);
201+
currentScope.$emit('$includeContentLoaded');
202+
scope.$eval(onloadExp);
203+
});
207204
}).error(function() {
208205
if (thisChangeId === changeCounter) cleanupLastIncludeContent();
209206
});

test/ng/directive/ngIncludeSpec.js

-25
Original file line numberDiff line numberDiff line change
@@ -280,31 +280,6 @@ describe('ngInclude', function() {
280280
dealoc(element);
281281
}));
282282

283-
it('should compile only the inner content once', function() {
284-
var log = [];
285-
286-
module(function($compileProvider) {
287-
$compileProvider.directive('compileLog', function() {
288-
return {
289-
compile: function() {
290-
log.push('compile');
291-
}
292-
};
293-
});
294-
});
295-
296-
inject(function($compile, $rootScope, $templateCache) {
297-
$templateCache.put('tpl.html', [200, '<div compile-log>123</div>', {}]);
298-
element = $compile('<div><div ng-include="exp"></div></div>')($rootScope);
299-
300-
$rootScope.exp = 'tpl.html';
301-
$rootScope.$digest();
302-
303-
expect(element.text()).toBe('123');
304-
expect(log).toEqual(['compile']);
305-
});
306-
});
307-
308283

309284
describe('autoscoll', function() {
310285
var autoScrollSpy;

0 commit comments

Comments
 (0)