AngularJS 2 has huge changes compared to the current generation. I personally think it should be named something other than AngularJS. A lot of people argue for and against the changes, or giving up on the framework completely.
Here is an example TodoMVC with a single component written in AngularJS 2
@Component({
selector: 'todo-app',
template: new TemplateConfig({
url: '/todo.html'
})
})
class TodoApp {
todos;
constructor() {
this.todos = ['item 1', 'item 2'];
}
}
The top part is just an annotation (the "A" in AtScript) and declared how the component instance
will be rendered (when the page uses <todo-app>
, the component's template comes from file todo.html
).
@Component({
selector: 'todo-app',
template: new TemplateConfig({
url: '/todo.html'
})
})
The bottom part is plain ES6 (in this case there are no dependency injection annotations)
class TodoApp {
todos;
constructor() {
this.todos = ['item 1', 'item 2'];
}
}
I like the clear separation between the template (using annotation) and the model (regular ES6 class). Makes the model much simpler to unit test. I will skip the template example, because the current template syntax right now looks crazy, and probably will change.
Learning resources
- From 1.3 to 2.0: Angular's Next Step
- Thoughts on ngEurope and Angular2
- All about Angular 2
- Angular 2 status preview and other links
AngularJS 2 Todo app
AngularJS 2 libraries:
Short comparison between various languages doc
Interesting for comparing ES6 / AtScript using AngularJS 1.3:
- ES6 features lukehoban/es6features
- angular 1.3 + ES6 modules angular-es6-seed
- angular 1.3 + AtScript + ES6 modules angular-atscript-seed
Transitioning from 1.x to 2.0
There is no official guide yet, because v2 is not ready yet. A little bit of advice judging by the things that were removed:
- Read Preparing for the future of AngularJS
- Do not use stand alone controller functions
- Use custom directives with their own controller functions
- Instead of scopes, use
controller as
syntax - Start using ES6 modules for structuring everything but the angular modules themselves
- Learn and take advantage of new features in ES6 - there are lots of them.
- Go through this online course
- Start writing small pieces using ES6, see Playing with ES6 code
- Play with 6to5 and traceur
Update 1
6to5 is now called Babel