Key differences between Angular 1.x & Angular 2
- Angular 2 is not an upgrade of Angular 1 but it is completely rewritten.
- Angular 2 uses TypeScript which is a superset of JavaScript (It doesn’t mean only TypeScript but dart also).
- Angular 1.x was not built with mobile support in mind, where Angular 2 is mobile-oriented.
- Angular 1's core concept was $scope but you will not find $scope in Angular 2.0 and above.
- Angular 1.x Controllers are gone in Angular v2. We can say that Controllers are replaced with “Components” in Angular 2.
- In Angular 2, Structural directives syntax is changed. ng-repeat is replaced with *ngFor.
- In Angular 2, local variables are defined using hash(#) prefix.
- Two-way data binding: ng-model has been replaced with [(ngModel)]
- Angular 2 uses Hierarchical Dependency Injection system which is the major performance booster of it.
- Angular 2 implements unidirectional-tree based change detection which, again, increases the performance.
- If you compare the file size, Angular 2 is 20 kb less than Angular 1 which helps in decreasing the load time for apps.
- Angular 2 provides more choice for languages. You can use any of the languages from ES5, ES6, TypeScript or Dart to write Angular 2 code while Angular 1.x had ES5, ES6, and Dart only. Addition of TypeScript is a great step as TypeScript is an awesome way to write JavaScript.
- To filter output in our templates in Angular 1.x, we used the pipe character (|) and one or more filters. Now, in Angular 2, they are called pipes. The syntax remains same.
- Angular 2 uses camelCase syntax for built-in directives. For example, ng-class is now ngClass and ng-model is now ngModel.
- One of the biggest advantages of Angular is Dependency Injection. In Angular 2, DI is there but now there is a different way to inject dependencies. As everything is a class in Angular, so DI is achieved via a constructor.
- In Angular 1.x, we can define a service via 5 different ways.
- Factory
- Service
- Provider
- Constant
- Values
And, in Angular 2, class is the only way to define a service.