Recently, Angular 2 was released and it has some fundamental changes compared to Angular 1. Why is it better than the previous version? Are there any projects that are not suitable to be built with Angular 2? Can Angular 1 be seamlessly upgraded to 2? You will find answers below.
4 reasons why Angular 2 rules
The most annoying feature of AngularJS 1.x is that we can’t add anything dynamically. In contrast, in Angular 2 we can create a component, configure a router and register a service in a pleasant way. One of the basic concepts of Angular 2 is that after clicking on some menu item we can dynamically pull the part of the application responsible for the application display. To do it in Angular 1 we had to hack the framework, use undocumented functions and gaps in the framework – things that we actually shouldn’t do.
Angular 2 is entirely component-based. This feature enforces thinking in components and as a result we get application that is neatly and naturally divided into separate parts - at least if you don’t create one component for the entire subpage. Component-based application development is usually faster due to easy creation and reasoning. Well designed components are also reusable which makes an application code more coherent.
3 Dependency injection
There is a simpler, more intelligible dependency injection container in Angular 2. Few developers knew the difference between provider, service and factory in Angular 1 and there is no such problem in Angular 2. Now the default setting is class instance - only if you want to use a different raw value you need to declare it explicitly using easily understandable object literal.
4 TypeScript usage
Angular 2 uses TypeScript and variety of concepts common in back-end. That is why it is more back-end developer-friendly. It's worth noting that dependency injection container makes use of metadata generated by TypeScript. Moreover, TypeScript usage improves developer experience thanks to good support from text editors and IDE's.
Disadvantages of Angular 2
Angular 2 is unquestionably better when architecture and code are considered, but Angular 1 has been there for a long time, so it had time to adapt to market, users, support and libraries. Developers had more time to find bugs and fix them. We can say it is more stable - and for some it may be a crucial argument to use Angular 1 instead of the newest version.
For the time being we see only one potential problem with Angular 2 - the amount of libraries. We need to create them by hand (however, based on the way how Angular 2 works it is quite easy), whereas in Angular 1 there are many integrations with external libraries.
Also, if you think about Angular as a jQuery on steroids, we advise you to use Angular 1, because it is closely tied with jQuery and there are many elements that are directly in the documentation.
Last but not least, you need to remember that Angular 2 is designed for business apps where code quality, adding extra features and ability to react to changes matters. You shouldn’t use it to build animated sites, loaded with bells and whistles, or games, because it will slow them down.
Migration from Angular 1 to 2
An app written in Angular 1 can be quite seamlessly upgraded to Angular 2 - the prerequisite is clean code and the use of Angular 1.5 components.
To do it smoothly we advise you to do it in two phases: first, modify the legacy into easy to upgrade version and second, upgrade it to Angular 2. Ng-upgrade module will help you to run Angular 1 and Angular 2 as one application. You need to register all services in 1 or 2, then register components at the same time in 1 and 2. At the end of this process you'll get almost whole application in Angular 2 so you can rewrite the last part and cut it off. Voila! You have whole application in Angular 2.
It is worth mentioning that migration process allows to work on new features at the same time.
But first you need to decide, if you or your client really needs to upgrade, because the whole process is time and money consuming. If an application is big it can take much more than a month for one developer to migrate it to Angular 2.
To sum it up, Angular 2 rules in terms of code and architecture. Unlike its predecessor, it is dynamic, component-based, has simple dependency injection and uses TypeScript. The main problem we see is the few integrations with external libraries (hopefully it will change with time). You can seamlessly migrate from Angular 1 to Angular 2, however you need to be prepared that it will take time. Are you ready for an upgrade?