This article is made to reassure the developers currently working on AngularJS to opt for an upgrade to the second version of the platform.
Here are the three theses to the advantage of using Angular 2 for your project:
- The second version is a competent and carefully designed high-performance framework;
- The platform has a lower entry barrier compared to the first version;
- A proper documentation and many application examples are available.
Let’s have a look at the differences in detail.
AngularJS does not provide a lot of freedom for your actions. You cannot turn over a fresh leaf and start to develop the architecture, data structure, components, various abstractions etc. The first version of the platform stipulates the certain types of modules and services to comply with. It is impossible to create a class of components from the ground up without matching the framework requirements. A developer using the version 1 always has numerous questions like “Which service type to choose from ‘value’, ‘constant’ or ‘factory’?” and many others related.
The rewrite of the platform does not provide such limitations. You can use any modular system, name and attach a random code.
A command line interface enabling the generation of apps, modules, components, directives, pipes (former name of filters), the launch of testing or code verification and many other useful features. All these requires only one command – ‘ng new app-name’. As a result, the required infrastructure will be created. Nothing in excess and you can start working.
All this blend enables you to create a more stable and beautiful code and releases from using the nasty JSDoc everywhere.
Angular v.2 does not have controllers but only components. A new component can be created via the command ‘ng generate component playground/player’. A baseline component code contains an implementation file, template file, file of styles with an extension of the used CSS preprocessor, and a unit-test file.
As you know, the main peculiarity of AngularJS is two-way binding. It is implemented in the second version via the transfer of a source property value, subscription to the event called “name of property inside child component” plus “change”, and the change of properties in a parent component at event occurrence.
For example, a template entry ‘<app-player [(position)]=”playerPosition”></app-player>’ transfers a property value of ‘playerPosition’ of the current component and it will change it upon any change of property of ‘position’ inside ‘player’ component. The key difference is a new syntax using the square brackets.
Such implementation caused an elimination of watchers that previously were the reasons for the numerous performance issues.
Compliance with the SOLID principles
In Angular, the issues associated with a high level of code cohesion are solved by a new mighty implementation of Dependency Injection and the possibility to abstract from the implementations of various interconnected components through the interfaces.
The routing on the v.2 has some pleasant improvements compared to the previous version. For example, you can dynamically load some bulky application module if it is used seldom. All the request starting with ‘/profile’ including ‘/profile/photo’, ‘/profile/orders/’, and ‘/profile/orders/:id’ will be processed by ProfileModule, which will be downloaded at the first need.
Low Barrier of Entry
In this article, you can find a small part of all features implemented in the second version of Angular. A lot of things like main services, asynchronous operations, reactive programming and others remained untold.
To sum up, AngularJS is a professional platform but its upgrade offers a new level of usability and comfort for the creation of high-quality products. As a result, when you taste the features of Angular 2, you will not want to get back to the first version.