Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

feat($compile): support dynamic transclusion slots #14227

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

odolha
Copy link

@odolha odolha commented Mar 13, 2016

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.

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.
@Narretz
Copy link
Contributor

Narretz commented Mar 14, 2016

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.

@odolha
Copy link
Author

odolha commented Mar 16, 2016

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
Copy link

+1

@nmindz
Copy link

nmindz commented Nov 23, 2016

+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 transclude: { ... } syntax.

@rodonako
Copy link

+1

1 similar comment
@premkumar-gg
Copy link

+1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants