- Notifications
You must be signed in to change notification settings - Fork27.4k
feat($compile): support dynamic transclusion slots#14227
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Make the 1.5+ multi-slot transclusion even more powerful. Allow the slots to be defined dynamically by component consumers, so components become more abstract, while template injection is clean and flexible.
I'm not a big fan, as it makes the API even more complex and I don't really see a big requirement of having an arbitrary number of transclusion slots. But let's see what others have to say. |
Indeed it makes it a bit more complex. Yet, in all fairness - multi-slot transclusion itself is still new, makes things more complex but it was really necessary (in my opinion). Personally I've encountered the requirements for this to be dynamic very soon after migrating to 1.5. One use case is explained in the example I provided. Currently we duplicate some code because this feature is missing, particualary template code. We considered various other approaches, particulary using 'require' and extending controllers. The only feasable and readable approach we found so far is to extract parts of the abstract component into other smaller components (e.g. the header and content cells of a table) and then re-asamble them into the specific needs of each case. Of course other more unintuitve ways to avoid code duplication are possible (e.g. writing some content manipulation directives), but we prefer a clean, clear and simple direction. If anyone has other suggestions on how to solve the use case without dynamic slots, let's discuss. |
dapriett commentedJul 23, 2016
+1 |
nmindz commentedNov 23, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
+1. This would reduce a few of my templates by aprox. 80% of it's original length if I were able to use an arbitrary number of transclusion slots w/o being bound by the |
rodonako commentedJan 10, 2017
+1 |
1 similar comment
premkumar-gg commentedJan 30, 2017
+1 |
New feature: dynamic transclusion slots.
Currently (1.5.x), a directive/component with transclusion slots must specify up-front the slots, using the transclude: { ... } approach.
With this PR, it is possible for consumers of such a directive/component to specify the transclusion slots themselves (in a special attribute called 'transclude-slots' which will be parsed before the component is compiled). This allows more abstract and flexible components - see the new example added in ngTransclude docs.
This PR doesn't introduce any breaking change.
Reference issue (starting point for PR work):http://stackoverflow.com/questions/35165202/angular-multiple-transclude-dynamic-number-of-elements.