-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Conversation
+1 for using some other marker to find the injection point. You should not be using transclusion at all here as the content of the element containing the ui-select directive is used as a template not a transclusion. Instead, make the directive terminal and then do the manipulation directly on the element where you wish to inject as part of the compile function. Then as you do, call $compile on the contents of the directive's element. |
@petebacondarwin at the compile function of the uiSelect directive, what I'd get from the tElement is the template of this directive and not what the user added on-the-fly on the directive, that's why I'm using transclusion, to get the content of what the user wrote inside the directive. I created this plunker with the compile function added to the uiSelect directive and a console.log of the tElement Let me know your comments please |
@dimirc - yes, if you provide a template I think it gets inserted before you get to the compile function. In that case you need to terminate the directive and do the template bit yourself.
|
@petebacondarwin I like the idea of using a directive as marker of injection point. Take a look at this commit basically I'm doing a directive very simillar to ngTransclude but also with the option to specify a class so that we only inject part of the transcluded content in that specific marker and not all. That's needed on the select template where we have 2 injection points. I only found one problem, and is that an exception is shown complaining about a parent controller not found even when the directive is working correctly. You could check this at console from this plunker. Maybe this has to do with how internally controllers are bound when using transcludeFn but I have no idea what to do here. PD: there are some failing test that I could check later, first I want to check better this alternative |
I still don't find a way to prevent those exceptions. They might be caused because we're calling the transcludeFn twice for same content since we only need part of the content for each marker. If I only use the directive once (for all transcluded content or part of it) it works correctly without any exception, but when I use the directive as a sibling then this problem shows. I found a related directive that could help, but I don't think the effort will be worth and we could keep the marker classes for now |
@dimirc I am afraid you are stretching the limits of what can be achieved with transclusion and templates. You may well need to just make the uiSelect directive terminal and then deal with all this manually. |
Fixes transclusion on angular v1.2.18+
We'll keep using classes to mark injection points for now |
For anyone else having this issue even though it was fixed, check your Angular version. I was running 1.2.16, and updating to 1.2.26 solved this issue. |
The choices template needed
ng-tranclude
, but it won't work anymore the same way since angular changed/corrected the way the transclusion and the scope bound.The alternative could be to use a new class
ui-select-choices-row-inner
instead ofng-transclude
to mark the location where we want to put the transcluded content by calling the transcludeFn from link function.Working plunker
Fixes: #85
Fixes: #80