Introduction
Angular is a platform to develop Web and mobile applications. Angular 2 is not just an update of Angular 1.x but Angular 2.0 is re-written and has many breaking changes. It is completely written in typed script (to meet ES 6 specifications). There will be a huge learning curve for the developers of Angular 2.
Difference between Angular 1.x and Angular 2.0

No Controller and $Scope
Angular 1.x is required to create a Controller and $scope. Both no longer exist in Angular 2.0. Angular 1.x’s Controller is replaced with the component in Angular 2.0.
Angular 1.x
- varmyApp = angular.module("myApp", [])
- .controller("empController", function($scope) {
- $scope.name = "Jignesh Trivedi";
- });
- import { Component } from 'angular2/core';
- @Component({
- selector: 'mydata',
- template: `
- <h3>{{name}}</h3> `
- })
- export class ProductComponent {
- name = "Jignesh Trivedi;
- }
Way of Bootstraping Angular Application is changed
Angular 1.x has two ways to bootstrap Angular.
- Using directive ng-app.
- Using Angular.bootstrap function.
Angular 2.0 has only one way to bootstrap Angular Application, using the bootstrap function.
- import { bootstrap } from 'angular2/platform/browser';
- import { TestComponent } from './Test.component';
- bootstrap(TestComponent);
ng-repeat directive is now replaced by *ngFor. ng-If is replaced with *ngIF. Angular 2.0. Camel Case syntax and Asterisk (*) sign is used as a prefix for the structural directives.
Angular 1.x
- <ul>
- <li ng-repeat="name in memberNames">
- {{name}}
- </li>
- </ul>
- <div ng-if="memberNames.length">
- <h3>You have {{memberNames.length}} Members.</h3>
- </div>
- <ul>
- <li *ngFor="let name of memberNames">
- {{name}}
- </li>
- </ul>
- <div *ngIf="memberNames.length">
- <h3>You have {{memberNames.length}} Members.</h3>
- </div>
Built-in directives syntax is changed
Angular 2.0 uses Camel case syntax for built-in directives. For example, ng-class is replaced with ngClass, ng-model is replaced with ngModel etc.
Event Syntax is changed
Angular 2.0 directly uses the valid HTML DOM element events. For example, ng-click is now replaced with (click)
Angular 1.x
- <button ng-click="clickEvent()">
- <button (click)="clickEvent()">
Angular 2.0 directly uses the valid HTML DOM element properties. Due to these changes, many built-in directives of Angular 1.x are now no longer required. For example, ng-href, ng-src, ng-show and ng-hide is no longer required. Angular 2.0 use href, src and hidden instead of ng-href, ng-src, ng-show and ng-hide directive.
One way data binding directive replaced with [property]
ng-bind directive is used for one way binding in Angular 1.x. Angular 2.0 uses HTML DOM element property for one way binding.
Angular 1.x
- <input type="text" ng-bind="name"></input>
- <input type="text" [value]="name"></input>
Two way data binding: ng-model replaced with [(ngModel)]
ng-model directive is used for two way data binding in Angular 1.x, but it is replaced with [(ngModel)] in Angular 2.0.
Angular 1.x
- <input type="text" ng-model="name"></input>
- <input type="text" [(ngModel)] ="name"></input>
There are five different ways to define the Service in Angular 1.x.
- Service
- Factory
- Constant
- Provider
- Values
Angular 2.0 has only one way to define the Service.
- import { Injectable } from 'angular2/core';
- @Injectable()
- export class DataService {
- constructor(public http: Http) {
- this.http = http;
- }
- getTestData() {
- return this.http.get("/api/Home/GetTestData")
- .map((responseData) =>responseData.json());
- }
- }
Way of routing is Changed- syntax changed
$routeProvider is used to configure routing and ng-view is used to load the view in Angular 1.x. In Angular 2, these are replaced with @RouteConfig and <router-outlet>respectively.
Angular 1.x
- var app = angular
- .module("MyModule", ["ngRoute"])
- .config(function ($routeProvider) {
- $routeProvider
- .when("/home", { templateUrl: "home.html", controller: "homeController" })
- })
- .controller("homeController", function ($scope) {
- $scope.message = "This is Home Page";
- })
- <ul>
- <li><a ng-href="#page4">Home</a></li>
- </ul>
- import { Component } from 'angular2/core';
- import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from 'angular2/router';
- @Component({
- selector: 'my-app',
- templateUrl: 'app/app.component.html',
- directives: [ROUTER_DIRECTIVES],
- providers: [
- ROUTER_PROVIDERS
- ]
- })
- @RouteConfig([
- { path: '/home', name: 'Home', component: HomeComponent, useAsDefault: true },
- ])
- export class AppComponent { }
- <ul>
- <li><a [routerLink]="['Home']" href="">Home</a></li>
- </ul>
Angular 2.0 supports TypeScript as development language whereas Angular 1.x is not supporting TypeScript.
Summary
Angular 2.0 is completely different from Angular 1.x. It requires some effort to migrate from Angular 1.x to Angular 2.0. Angular 2.0 implements web standards, for example, component, and it provides better performance than Angular 1.x.


Vinod AbrahamPosted Sep 23, 2017, 9:13 PM EDT
Very valuable stuffs
Kunal VaishyaPosted Sep 17, 2016, 12:04 AM EDT
Nice Article
Vivek KumarPosted Aug 10, 2016, 12:19 AM EDT
Nicely explained.
Lakshmanan Sethu SankaranarayanPosted Jul 17, 2016, 9:31 PM EDT
Good one
Sanjay SabariyaPosted Jul 7, 2016, 8:32 PM EDT
Thanks for sharing knowledge.
Naveen BishtPosted Jun 30, 2016, 10:54 PM EDT
Hi very nice...
Anupam SinghPosted Jun 30, 2016, 1:44 AM EDT
Thanks for sharing buddy, well written.. everything in one place..
Ravi PatelPosted Jun 30, 2016, 1:17 AM EDT
Nice
Shantha Kumar TTOP 100Posted Jun 29, 2016, 9:27 PM EDT
Thanks for the article
Santhakumar MunuswamyPosted Jun 29, 2016, 8:58 PM EDT
Thank you for nice article
Jignesh TrivediTOP 100Posted Jun 29, 2016, 2:03 AM EDT
Thank you all for reading my article.
kalu singh raoPosted Jun 28, 2016, 9:27 PM EDT
Nice one...
Guest UserPosted Jun 28, 2016, 7:05 PM EDT
Cool. i enjoyed reading this article. Ang2.0 differs a lot than 1.0
Kuppurasu NagarajTOP 100Posted Jun 28, 2016, 10:12 AM EDT
Nice Sharing..
Debasis SahaTOP 100Posted Jun 28, 2016, 7:42 AM EDT
Nice share