Why should you use Angular 2 ? What are the Advantages of Angular 2 ?
The core differences and many more advantages on Angular 2 vs. Angular 1 as following,
Angular 2 vs. Angular 1 | Angular 4 vs. Angular 2 | Angular 5 vs. Angular 4 | Angular 6 vs Angular 5 |
The core differences and many more advantages on Angular 2 vs. Angular 1 as following,
1. It is entirely component based.
2. Better change detection
3. Angular2 has better performance.
4. Angular2 has more powerful template system.
5. Angular2 provide simpler APIs, lazy loading and easier to application debugging.
6. Angular2 much more testable
7. Angular2 provides to nested level components.
8. Ahead of Time compilation (AOT) improves rendering speed
9. Angular2 execute run more than two programs at the same time.
10. Angular1 is controllers and $scope based but Angular2 is component based.
11. The Angular2 structural directives syntax is changed like ng-repeat is replaced with *ngFor etc.
12. In Angular2, local variables are defined using prefix (#) hash. You can see the below *ngFor loop Example.
13. TypeScript can be used for developing Angular 2 applications
14. Better syntax and application structure
There are more advantages over performance, template system, application debugging, testing, components and nested level components.
For Examples as,
Angular 1 Controller:-
var app = angular.module("userApp", []); app.controller("productController", function($scope) { $scope.users = [{ name: "Anil Singh", Age:30, department :"IT" }, { name: "Aradhya Singh", Age:3, department :"MGMT" }]; });
Angular 2 Components using TypeScript:-
Here the @Component annotation is used to add the metadata to the class.
import { Component } from 'angular2/core'; @Component({ selector: 'usersdata', template: `<h3>{{users.name}}</h3>` }) export class UsersComponent { users = [{ name: "Anil Singh", Age:30, department :"IT" }, { name: "Aradhya Singh", Age:3, department :"MGMT" }]; }
Bootstrapping in Angular 1 using ng-app,
angular.element(document).ready(function() { angular.bootstrap(document, ['userApp']); });
Bootstrapping in Angular 2,
import { bootstrap } from 'angular2/platform/browser'; import { UsersComponent } from './product.component'; bootstrap(UserComponent);
The Angular2 structural directives syntax is changed like ng-repeat is replaced with *ngFor etc.
For example as,
//Angular 1, <div ng-repeat="user in users"> Name: {{user.name}}, Age : {{user.Age}}, Dept: {{user.Department}} </div> //Angular2, <div *ngFor="let user of users"> Name: {{user.name}}, Age : {{user.Age}}, Dept: {{user.Department}} </div>
Angular 2 Docs
Angular 4 and Angular 5 Fundamental Concepts
I hope you are enjoying with this post! Please share with you friends!! Thank you!!!