material icon indicating copy to clipboard operation
material copied to clipboard

md-checkbox throws [ngTransclude:orphan] when used inside a directive using transclusion

Open ACDN opened this issue 11 years ago • 15 comments

Here is the error that get's reported.

Error: [ngTransclude:orphan] Illegal use of ngTransclude directive in the template! No parent directive that requires a transclusion found. Element:

Will try and get a plunker setup to demo this. Though may take me sometime. For now I just wanted to get the error in.

ACDN avatar Dec 10 '14 19:12 ACDN

I'm gonna close this. Try it with the newest version and the newest Angular.

Please reply if you keep finding issues.

ajoslin avatar Jan 14 '15 08:01 ajoslin

Hi, I just tried it with the latest version and Angular 1.3.8. Still throws the same error.

Error: [ngTransclude:orphan] Illegal use of ngTransclude directive in the template! No parent directive that requires a transclusion found. Element:

http://errors.angularjs.org/1.3.8/ngTransclude/orphan?p0=%3Cdiv%20ng-transclude%3D%22%22lass%3D%22md-label%20ng-scope%22%3E at angular.js:63:12 at ngDirective.link (angular.js:25210:35) at invokeLinkFn (angular.js:8213:9) at nodeLinkFn (angular.js:7722:11) at compositeLinkFn (angular.js:7075:13) at publicLinkFn (angular.js:6954:30) at boundTranscludeFn (angular.js:7093:16) at controllersBoundTransclude (angular.js:7749:18) at ngDirective.link (angular.js:25217:5) at invokeLinkFn (angular.js:8213:9)

ACDN avatar Jan 14 '15 22:01 ACDN

@ACDN - if you provide a Plunkr or CodePen that demonstrates this issue, we will reopen and address it.

ThomasBurleson avatar Jan 15 '15 04:01 ThomasBurleson

Will try to. Is there a plunkr that I could use as a starting point?

On Wed, Jan 14, 2015 at 9:52 PM, Thomas Burleson [email protected] wrote:

@ACDN https://github.com/ACDN - if you provide a Plunkr or CodePen that demonstrates this issue, we will reopen and address it.

— Reply to this email directly or view it on GitHub https://github.com/angular/material/issues/900#issuecomment-70039689.

ACDN avatar Jan 15 '15 20:01 ACDN

@ACDN Here's the one I'm using: http://plnkr.co/edit/G0CCmRfi9CHxCPkwkiND?p=preview It's empty, but should have all the relevant includes.

PaulMougel avatar Jan 15 '15 20:01 PaulMougel

Thanks that really helped me put this together quicker.

Here is the link to the plnkr that shows the issue: http://plnkr.co/edit/a9hQkClEce5RPEILZCc1?p=preview

In the xui-table I have placed a MD-CHECKBOX. You can see in the live preview that 2 are being displayed and if you check the console output you'll see the error that I posted earlier in this thread.

ACDN avatar Jan 15 '15 21:01 ACDN

unable to reproduce.

ThomasBurleson avatar Jan 31 '15 01:01 ThomasBurleson

Why was this closed as unable to reproduce when a plunkr was provided that shows the error?

dpaquette avatar Feb 04 '15 19:02 dpaquette

I was wondering the same thing.

ACDN avatar Feb 04 '15 19:02 ACDN

@ACDN - the plunkr you provided is simply too complicated to triage the issue.

So I created a simple CodePen test with a custom directive performing transclusion: http://codepen.io/ThomasBurleson/pen/MYvdNv. My own tests do not manifest the error: "Error: [ngTransclude:orphan] Illegal use of ngTransclude directive in the template! No parent directive that requires a transclusion found."

I am unable to reproduce the error in my tests. So I closed the issue.


Your demo uses the xui-table directive with a transclude:true option. But the template does not have a ng-transclude attribute directive. Hence the error.

ThomasBurleson avatar Feb 04 '15 20:02 ThomasBurleson

@ThomasBurleson Your attempt to reproduce may have been too simplistic. I believe this problem is related to more complex custom transclusion scenarios. I will work on a sample to show the problem. I am also have similar issues with a number of md directives.

dpaquette avatar Feb 04 '15 20:02 dpaquette

I have reproduced this error here on CodePen: http://codepen.io/anon/pen/myBYyX

This was the simplest example I could create to show the problem. While it may not seem realistic, it is representative of what I am seeing when I try to use material design directives inside of https://github.com/stevenh77/drop-ng and other 3rd party angular directives.

dpaquette avatar Feb 04 '15 21:02 dpaquette

@ThomasBurleson @dpaquette To add to this, I narrowed it down a bit: http://plnkr.co/edit/rzVBw3eOejQCWkzhG75y?p=preview

Notice that when we receive the clone, the <md-checkbox> template has already been applied. I suspect that this is the issue.

robertmesserle avatar Feb 04 '15 21:02 robertmesserle

@dpaquette - Thanks for contributing this more-easily introspected sample. In your CodePen it appears that you are incorrectly compiling the clone

var compiled = $compile(clone)(scope);

When you call a transclude function it returns a a jqLite/JQuery object that contains the compiled DOM, which is linked to the correct transclusion scope. When you call a transclusion function you can pass in a clone attach function. This function accepts two parameters, function(clone, scope) { ... }, where the clone is a fresh compiled copy of your transcluded content and the scope is the newly created transclusion scope, to which the clone is bound.

Since you are indeed using a clone attach function, If I do this:

var divForTransclusion = angular.element(element[0].querySelector('.contentGoesHere')); 
divForTransclusion.append(clone);

then I do not detect an error. Am I missing a technical detail or issue?

ThomasBurleson avatar Feb 05 '15 04:02 ThomasBurleson

Should this be already fixed? I'm having the same problem with version 1.0.8 (angular 1.5.6).

andrehil avatar May 31 '16 20:05 andrehil