r/angularjs • u/panzerdp • Jun 13 '16
A new Angular 1.x ES2015 styleguide, the path to Angular 2
https://toddmotto.com/rewriting-angular-styleguide-angular-21
Jun 13 '16
Page is down?
2
u/toddmotto Jun 13 '16
Works on my machine
1
Jun 13 '16
Looks like it's working now for me as well. Weird.
2
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.
2
u/toddmotto Jun 14 '16
Found this neat article, added to the guide: https://github.com/toddmotto/angular-styleguide/commit/2d4305e77a9cedc058713998efa92accdeefd374
1
u/mrc1897 Jun 14 '16
@Todd : thanks for the guide-- very informative post. Few questions
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.
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
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
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
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 :)
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.