Transcluded element with child directive and ng-repeat cannot find required parent directive

93 views
Skip to first unread message

Brian Guetzlaff

unread,
Apr 29, 2016, 12:41:09 PM4/29/16
to AngularJS
Hi all, this is similar to an older bug (issue 4935: https://goo.gl/f1A9RW) but am seeing it on 1.3.13 (also 1.5.5).  Basically, I have a parent directive that uses transclusion.  The transcluded content is an element with a child directive that is ng-repeated.  Here's a Plunk that shows the same problem using ng-if instead of ng-repeat:  http://plnkr.co/edit/HZO9goSDcKHIrWWPyr6S?p=preview

If you look in your debug console, you'll see this:
angular.js:13550 Error: [$compile:ctreq] Controller 'main', required by directive 'sub', can't be found!

Stepping through the code, it looks like the clone goes through its link phase prior to actually being added to the DOM.  While I can understand why this is the case, it also means that the parent directive requirements cannot be met as there is no parent hierarchy to search.

Is this by design, or can assumptions be made based on the futureParentElement for transclusion (using default parent element at least for this requirement search)?

Sander Elias

unread,
Apr 30, 2016, 1:55:00 AM4/30/16
to AngularJS
Hi Brian,

If you remove the ng-if. it still doesn't work. If you remove the transclude (which is actually not needed in the sample at all!) it works as intended. That makes this an intriguing issue. Sadly I do miss the time right now to dig in deeply, and come up with the related explanation. There are a couple of workarounds available if you really need to do something like this. You can traverse the DOM-tree upwards until you find your controller manually.

Regards
Sander


  
Reply all
Reply to author
Forward
0 new messages