mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
revert(ngInclude): remove ngInclude manual transclusion system
This commit is contained in:
parent
63e9ea18f8
commit
6749fef227
2 changed files with 16 additions and 44 deletions
|
|
@ -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();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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, '<div compile-log>123</div>', {}]);
|
||||
element = $compile('<div><div ng-include="exp"></div></div>')($rootScope);
|
||||
|
||||
$rootScope.exp = 'tpl.html';
|
||||
$rootScope.$digest();
|
||||
|
||||
expect(element.text()).toBe('123');
|
||||
expect(log).toEqual(['compile']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('autoscoll', function() {
|
||||
var autoScrollSpy;
|
||||
|
|
|
|||
Loading…
Reference in a new issue