Comparing Angular 1 and Angular 2
What is Angular?
To explain workload distribution, let me provide you with an example scenario…
Imagine you’re on a shopping website, and you’re looking at buying an Emoji Smiley Face ChiaPet. Even though you like the Smiley Face, you think you decide to check out the Winky Face option.
This is called a ‘post-back’. The vast majority of this data will be identical to the last page. Same site header, same CSS and page template, but you’re getting it all again because you want a houseplant with some attitude.
Most of the data between these two pages is the same.
This isn’t necessarily a problem if you’re using laptop with a decent Internet connection. But what about if you are on your phone, using your mobile data?
Browsers have become much more powerful in recent years. Angular takes advantage of this to take a large amount of work off the server and the Internet connection, and it shares more of the burden with the user’s browser.
Angular 1 Details
One of the things I realized when I started working with Angular 1 is how much faster it was to develop the UI. For example, if I wanted to list out the names of some employees, I could write something like this…
<div ng-repeat=”employee in employees”>
Want to let people search through that list? Just add a textbox and use it to filter the list!
<input type=”text” ng-model=”search” />
<div ng-repeat=”employee in employees | filter:search”>
That connects the list to the textbox and filters down the values shown to whatever the person entered.
It’s easily the difference between 16 hours of development time and 1 minute of development time.
Other great Angular features:
- Unit testing
- Script dependency handling
- Modular design patterns to help multiple developers work in parallel
- Single-page application
Angular 2 Details
On September 14, Angular 2 was — at long last — officially released. For more than a year prior, developers have been trying the Angular 2 release candidates in projects. These versions were not entirely stable and subject to changes that could break the project you were working on. Now with the official release, we should start to see many of the stability issues smooth out and no more breaking changes. However, many developers were trying to jump into using it before the official release because of some very exciting upgrades. The biggest update is the switch to TypeScript.
Angular 2 also has drastically reduced the size of their framework, which means less data needs to be sent to the user’s browser. In addition, they have modularized their framework, so you can cherry pick the features you want to use in case there are aspects your application doesn’t need. Or if you can do some functionality better with custom software, you can write your own module to replace Angular’s.
How To Decide Between Angular 1 and Angular 2
If you’re about to start a pet project, something short term with few developers, then it might be worth trying out Angular 2. Once you have your project’s build system running smoothly on your computer, development can be extremely fast and easy.
But if you have a project that is long term with many developers, I’d recommend Angular 1. In my experience, attempting Angular 2 projects with this size proves to be a burden. You end up spending a significant amount of time debugging problems with the build system not working properly and upgrades that have broken features.
With Angular 1, you can easily create a tried and tested seed project with a build system using the Yeoman scaffolding tool. I’m not saying you won’t run into issues with your development project, but in my experience these issues are far less frequent.
About a year ago, Dave Ceddia of The Angularity blog put together a flow chart to illustrate the process. His recommendations still ring true today.
This isn’t to say that my recommendation won’t change soon. Angular 2 was only just released officially a week ago. There will be bugs that need to get fixed, not just with Angular but also with the build systems developers use to create the projects. In a few months there is a good chance that a lot of the problems developers have encountered will be smoothed out. But I have no doubt that Angular 2 will be the future of web development.
Originally published at blog.springthrough.com.