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

Commit d4d298c

Browse files
jankucabtford
authored andcommitted
fix(ngTransclude): detect ngTranslude usage without a transclusion directive
Closes #3759
1 parent 742271f commit d4d298c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/ng/directive/ngTransclude.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@
5252
*
5353
*/
5454
var ngTranscludeDirective = ngDirective({
55-
controller: ['$transclude', function($transclude) {
55+
controller: ['$element', '$transclude', function($element, $transclude) {
56+
if (!$transclude) {
57+
throw minErr('ngTransclude')('orphan',
58+
'Illegal use of ngTransclude directive in the template! ' +
59+
'No parent directive that requires a transclusion found. ' +
60+
startingTag($element));
61+
}
62+
5663
// remember the transclusion fn but call it during linking so that we don't process transclusion before directives on
5764
// the parent element even when the transclusion replaces the current element. (we can't use priority here because
5865
// that applies only to compile fns and not controllers

test/ng/compileSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -2834,6 +2834,18 @@ describe('$compile', function() {
28342834
});
28352835

28362836

2837+
it('should throw on an ng-translude element inside no transclusion directive', function() {
2838+
inject(function ($rootScope, $compile) {
2839+
expect(function () {
2840+
$compile('<div><div ng-transclude></div></div>')($rootScope);
2841+
}).toThrowMinErr('ngTransclude', 'orphan',
2842+
'Illegal use of ngTransclude directive in the template! ' +
2843+
'No parent directive that requires a transclusion found. ' +
2844+
'<div ng-transclude="">');
2845+
});
2846+
});
2847+
2848+
28372849
it('should make the result of a transclusion available to the parent directive in post-linking phase (template)',
28382850
function() {
28392851
module(function() {

0 commit comments

Comments
 (0)