diff options
| author | Tobias Bosch | 2013-11-21 21:54:42 -0800 | 
|---|---|---|
| committer | Tobias Bosch | 2013-11-21 22:20:11 -0800 | 
| commit | 0a7cbb33b06778833a4d99b1868cc07690a827a7 (patch) | |
| tree | ced79c2c12dedd84e972b8fb29c543cbfcb6e5a1 /src/ng/directive/ngInclude.js | |
| parent | 579242346c4202ea58fc2cae6df232289cbea0bb (diff) | |
| download | angular.js-0a7cbb33b06778833a4d99b1868cc07690a827a7.tar.bz2 | |
fix(ngInclude): Don't throw when the ngInclude element contains content with directives.
Related to #5069
Diffstat (limited to 'src/ng/directive/ngInclude.js')
| -rw-r--r-- | src/ng/directive/ngInclude.js | 29 | 
1 files changed, 17 insertions, 12 deletions
| diff --git a/src/ng/directive/ngInclude.js b/src/ng/directive/ngInclude.js index 7f395f96..b721aa23 100644 --- a/src/ng/directive/ngInclude.js +++ b/src/ng/directive/ngInclude.js @@ -188,18 +188,23 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'                if (thisChangeId !== changeCounter) return;                var newScope = scope.$new(); -              $transclude(newScope, function(clone) { -                cleanupLastIncludeContent(); - -                currentScope = newScope; -                currentElement = clone; - -                currentElement.html(response); -                $animate.enter(currentElement, null, $element, afterAnimation); -                $compile(currentElement.contents())(currentScope); -                currentScope.$emit('$includeContentLoaded'); -                scope.$eval(onloadExp); -              }); +              // Note: This will also link all children of ng-include that were contained in the original +              // html. If that content contains controllers, ... they could pollute/change the scope. +              // However, using ng-include on an element with additional content does not make sense... +              // Note: We can't remove them in the cloneAttchFn of $transclude as that +              // function is called before linking the content, which would apply child +              // directives to non existing elements. +              var clone = $transclude(newScope, noop); +              cleanupLastIncludeContent(); + +              currentScope = newScope; +              currentElement = clone; + +              currentElement.html(response); +              $animate.enter(currentElement, null, $element, afterAnimation); +              $compile(currentElement.contents())(currentScope); +              currentScope.$emit('$includeContentLoaded'); +              scope.$eval(onloadExp);              }).error(function() {                if (thisChangeId === changeCounter) cleanupLastIncludeContent();              }); | 
