r/angularjs • • Nov 13 '15

Exploring the Angular 1.5 .component() method

http://toddmotto.com/exploring-the-angular-1-5-component-method
57 Upvotes

13 comments sorted by

4

u/chazzlabs Nov 13 '15

Why is transclusion enabled by default? If I'm creating a component with the default settings but not leveraging transclusion is there a small, unnecessary overhead cost there? We rarely use transclusion in our directives so the fact that it's enabled by default has me curious whether we're designing our directives correctly/optimally.

Great article overall though. I'm excited to use Component. We've been keeping on top of upgrading with each minor release, and so far it's been a breeze.

5

u/toddmotto Nov 13 '15

I think @elpropher answered nicely. Thanks for the feedback, excited to use it too! :)

6

u/elprophet Nov 13 '15

is there a small, unnecessary overhead cost there?

Not really; the cost is negligible to say that transclusion can happen (it's setting a flag during directive setup that has to be set one way or the other). The cost for transclusion is incurred when the transclusion actually happens; eg, when your component depends on and calls the $transclude function.

2

u/-pertinax- Nov 13 '15

Nice summary Todd. I was interested by this when I first heard about it at AngularConnect but at the time there were no docs, and the only mention I could find was in a pending pull request on GitHub. I also really like the fact that you included those snippets from the actual Angular source. Makes it clear exactly what is going on there.

2

u/toddmotto Nov 14 '15

Thank you! And yes likewise, so I did a little reading of the source and found it super useful, glad you liked the source snippets! :D

1

u/dvidsilva Nov 13 '15

random comment.

you say "property worth nothing" in the template section, did you mean worth noting?

2

u/toddmotto Nov 14 '15

Ah thank you - fixed :)

2

u/ogrechoker Nov 13 '15

canActivate is going to make it into 1.5???

2

u/antoninj Nov 13 '15

That's really awesome. I can't wait to see the release. I've been playing around with Angular 2 and absolutely love it but I'm stuck on Angular 1.4 at work.

1

u/xCavemanNinjax Nov 14 '15

The template property can be defined as a function that is now injected with $element and $attrs locals. If the template property is a function then it needs to return an String representing the HTML to compile:

This reminds me of a react component with props and a render function.

1

u/vivainio Nov 14 '15

My earlier question was downvoted to oblivion for unknown reasons, so making a new post:

Has anyone tried using this new API with ES6 class syntax yet? Clearly, using just the plain ES5 api is not a problem either (i.e. have your controller as a class and 'component' declaration as a function), but it would be interesting to see if you can get some extra goodies from ES6 classes.

-8

u/vivainio Nov 13 '15

What's the es6 story here? Too lazy to google right now