Skip to content
Advertisement

AngularJS Multi-slot transclusion

I am trying to implement a component in AngularJS 1.5.8 with multi-slot transclusion.

My test works fine if I use a directive, but with a component, it seems like not even the slot is found!.

This is how I declare the component

JavaScript

And here the HTML

JavaScript

Official AngularJS documentation says

In AngularJS, a Component is a special kind of directive that uses a simpler configuration which is suitable for a component-based application structure.

If this is the case, then multi-slot transclusion should work perfectly with components as well.

I know I am missing something, but I cannot see what it is!

I have crated a small Plunker with both a directive and a component.

https://plnkr.co/edit/yTMRD4SrH8CWLK4LQEwe?p=info

Thanks

Advertisement

Answer

For components, use an object (not a function):

JavaScript

Also, you’re missing $ctrl in {{ title }}. It should be:

JavaScript

Here it is working in a plnkr.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement