Transclude scope overrides ng-controller when on same (custom) directive

449 views
Skip to first unread message

Christophe Eymard

unread,
Feb 28, 2013, 4:52:58 PM2/28/13
to ang...@googlegroups.com
http://jsfiddle.net/pouipoui/X4rSy/1/

In it, we can see that using ng-controller on a custom directive causes a loss of the scope that it created.

What can be done to avoid the issue ?

Thanks for any input :)

Peter Bacon Darwin

unread,
Feb 28, 2013, 5:08:17 PM2/28/13
to ang...@googlegroups.com
I think this is a bug. I think that when you use replace:true the controller attached to the original element is not copied over.
Can you create an issue?
Pete


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Joshua Miller

unread,
Feb 28, 2013, 5:10:07 PM2/28/13
to angular
Hello!

Actually, this is the behavior I would expect. 

Transclusion means the contents of the element are evaluated in the *parent* scope. When you define a controller on the same element, you are creating a new scope, but the transcluded contents are still evaluated in the parent scope - that is, in the scope *above* the new controller. Adding an ngController directive to an element shouldn't change how tranclusion works on another directive.

Or am I completely off base here?

Josh


--

Peter Bacon Darwin

unread,
Feb 28, 2013, 5:32:56 PM2/28/13
to ang...@googlegroups.com
@Josh - yes, you are right!
There is a bug about controllers elsewhere though!
Pete

Peter Bacon Darwin

unread,
Feb 28, 2013, 5:34:16 PM2/28/13
to ang...@googlegroups.com

Christophe Eymard

unread,
Mar 1, 2013, 4:28:43 AM3/1/13
to ang...@googlegroups.com
Any idea how to work around that problem ?
Does it still warrant an issue report ?
If yes, did you fill one already or should one be filled ?

Peter Bacon Darwin

unread,
Mar 1, 2013, 2:09:37 PM3/1/13
to ang...@googlegroups.com

Christophe Eymard

unread,
Mar 1, 2013, 2:56:04 PM3/1/13
to ang...@googlegroups.com
I find it a little sad that we have to transclude the elements manually in the controller, kind of a performance loss there.

I hope we find some solution in the compile method...

Thank you though !


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/2Edcj4FKmSE/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.

To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Christophe Eymard

Peter Bacon Darwin

unread,
Mar 1, 2013, 3:11:56 PM3/1/13
to ang...@googlegroups.com

Christophe Eymard

unread,
Mar 1, 2013, 3:31:59 PM3/1/13
to angular
Ah, my bad, didn't think it through.

Thank you again !
Reply all
Reply to author
Forward
0 new messages