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

Commit 966daf6

Browse files
committed
fix(ngTransclude): detect ngTranslude usage without a transclusion directive
Closes angular#3759
1 parent 418d7a3 commit 966daf6

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
@@ -2798,6 +2798,18 @@ describe('$compile', function() {
27982798
});
27992799

28002800

2801+
it('should throw on an ng-translude element inside no transclusion directive', function() {
2802+
inject(function ($rootScope, $compile) {
2803+
expect(function () {
2804+
$compile('<div><div ng-transclude></div></div>')($rootScope);
2805+
}).toThrowMinErr('ngTransclude', 'orphan',
2806+
'Illegal use of ngTransclude directive in the template! ' +
2807+
'No parent directive that requires a transclusion found. ' +
2808+
'<div ng-transclude="">');
2809+
});
2810+
});
2811+
2812+
28012813
it('should make the result of a transclusion available to the parent directive in post-linking phase (template)',
28022814
function() {
28032815
module(function() {

0 commit comments

Comments
 (0)