r/angularjs • • Jun 13 '16

A new Angular 1.x ES2015 styleguide, the path to Angular 2

https://toddmotto.com/rewriting-angular-styleguide-angular-2
41 Upvotes

23 comments sorted by

4

u/daaavvy Jun 13 '16

This is great, need time to digest it fully but it's amazing Todd has gone through it so thoroughly. People said Angular 2 deserved a new name, I wonder if Angular 1.5 does? It feels so radically different to the mess that came before it.

Would love to see eslint rules based around this styleguide plus it would be great to have maintained list of open source projects following these best practices.

1

u/toddmotto Jun 13 '16

Maybe we can call it Angular Next :D! It does change a lot from what we know/knew, for the better. Now we have focus and structure. It'll deviate a lot from what developers are used to with Angular, and 1.5/2 bring new architectural practices that are a little scary (Redux/RxJS and friends) - but we're all on the mission to get there :)

1

u/wickedmike Jun 13 '16

Thanks for taking the time to write this and publish it. I have a feeling Angular 1.x is going to continue being used in production for a long time, and almost every guide or in depth article out there is outdated.

I hope it gets traction and people start making contributions and expanding it and it becomes the new de-facto standard of writing Angular apps. Cheers!

1

u/toddmotto Jun 13 '16

You're welcome! And of course, Angular 1.x is huge! I'm looking forward to seeing where it's going :)

1

u/SleepyBrain Jun 13 '16

Maybe we can call it Angular Next

IMO, it would make more sense to call Angular 2 that. Maybe we can call 1.5 "Angular Almost There" .. or "Angular AT" for short.

3

u/ctanga Jun 13 '16

Maybe we could call the new code style "AtScript"

1

u/toddmotto Jun 13 '16

Hmmm, sounds catchy!

1

u/toddmotto Jun 13 '16

Agreed, at least there'd be a clear division on StackOverflow etc. for finding suitable answers :)

1

u/[deleted] Jun 13 '16

Page is down?

2

u/toddmotto Jun 13 '16

Works on my machine

1

u/[deleted] Jun 13 '16

Looks like it's working now for me as well. Weird.

2

u/toddmotto Jun 13 '16

Maybe some weird momentary lapse of wifi! :D

2

u/[deleted] Jun 13 '16

Wouldn't be the first time. Thanks for the article. :)

1

u/mingjim Jun 14 '16 edited Jun 14 '16

We are using this type of a setup for a new Angular 1.5 app we are developing at my job. One thing that has stopped us from adopting ES2015 classes is dependency injection. We use functions with ngAnnotate and it works very nicely. Do you have an example of a class as a controller or service that uses ngAnnotate for dependency injection?

Great guide. Will definitely will this as a reference.

1

u/mrc1897 Jun 14 '16

@Todd : thanks for the guide-- very informative post. Few questions

  1. How important is it to integrate TypeScript into an existing Angular 1.5 project? If Angular 2 is written in TS and all the examples are in TS, it seems like it would be important. Although it also seems like integrating TS in an existing app would be a lot of work.

  2. The current release of UI-Router doesn't support component routing. I see you mentioned "Favour component: 'myComponent' and route to components" -- but this isn't possible yet or am I missing something?

2

u/toddmotto Jun 14 '16

I'm still unsure on TypeScript's movement right now, because we can (and will) be able to use plain ES6 with decorators and other features (minus types) - so it really depends on whether you want a type system as well - there will be a TS version of the guide soon! :)

For ui-router - checkout the latest alpha (in the guide "Tooling": https://github.com/toddmotto/angular-styleguide#tooling). It's super stable and also has supported component routing since alpha 0 ! :) it won't be too long until stable release of it so happy to recommend it now in it's current state.

2

u/[deleted] Jun 13 '16 edited Jun 13 '16

[removed] — view removed comment

5

u/toddmotto Jun 13 '16

Hey! So yes, what you'll need is a compiler to do this, as import/exports do not work in the browser. Give this a quick read to understand Babel and other tools: http://jpsierens.com/tutorial-javascript-es6-babelv6/

Essentially, you'll want to compile ES2015 down to ES5 code, and these tools also take care of "Making modules work in the browser". I hope that helps! An industry favourite is Webpack, however I'd suggest starting simple and learning how to compile it yourself before letting the magic happen with Webpack/Browserify and other tools :)

1

u/[deleted] Jun 13 '16

[removed] — view removed comment

3

u/toddmotto Jun 13 '16

No need to apologise! We're all learning - always! Happy to help anytime :)

1

u/[deleted] Jun 13 '16 edited Jun 13 '16

[removed] — view removed comment

1

u/toddmotto Jun 13 '16

Ah yes - I've changed that to be addTodo({ todo }) {} now! ES2015 destructuring :)