Open In App

AngularJS vs Angular2 | Features and Comparison

AngularJS is a front-end dynamic JavaScript framework, used for developing a ‘Single Page Application‘. AngularJS is managed by Google and is open-source. This means that it is open for contribution by developers around the globe. Due to this, there is a lot of material online available for free, to learn the technology. After its launch, AngularJS quickly became popular. This is because of the large set of functionalities it provided to the developers, like data binding, easier event handling, etc. 

AngularJS Features:



Example: This example describes the use of the ng-init directive in AngularJS.




<!DOCTYPE html>
<html>
 
<head>
    <script src=
    </script>
    <title>AngularJS ng-init Directive</title>
</head>
 
<body>
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h2>ng-init directive</h2>
    <div ng-app="" ng-init=
    "sort=['quick sort', 'merge sort', 'bubble sort']">
        Sorting techniques:
        <ul>
            <li>{{ sort[0] }} </li>
            <li>{{ sort[1] }} </li>
            <li>{{ sort[2] }} </li>
        </ul>
    </div>
</body>
</html>

Output:



 

Angular 2 is built on the ‘Typescript’. Typescript is an open-source programming language, managed by Microsoft. Angular 2 is completely different from AngularJS. AngularJS had features like controllers, $scope, $scope variables, etc. However, in Angular 2, these features were replaced by new features namely components and directives. 

Angular 2 Features:

Example: This example describes the use of the ng-model directive in Angular2.

app.component.ts:




import { Component, Inject } from '@angular/core';
import { PLATFORM_ID } from '@angular/core';
import { isPlatformWorkerApp } from '@angular/common';
 
@Component({
    selector: 'my-app',
    templateUrl: './app.component.html',
    styleUrls: [ './app.component.css' ]
})
export class AppComponent {
    gfg: string = '';
 
setValue() {
    this.gfg = 'GeeksforGeeks';
}
}

app.component.html:




<h1>GeeksforGeeks</h1>
<input [(ngModel)]="gfg" #ctrl="ngModel" required>
<p>Value: {{ gfg }}</p>
<button (click)="setValue()">Set value</button>

Output:

 

Difference between AngularJS vs Angular 2:

Factor

 Angular JS

Angular 2

Language

Written in JavaScript.

Written in TypeScript(a superset of Javascript).

Routing

$routeprovider.when() is used for routing configuration.

@RouteConfig{} is used for routing.

Architecture

Uses MVC architecture to build the applications.

Uses MVVM architecture to build the applications.

Mobile Support

AngularJS does not support mobiles.

Angular 2 was developed specifically to cater to mobile users.

Iteration “ng-repeat” is used to iterate through elements.  *ngFor is used to iterate through elements.
Complications

It is easier to learn. However, the application starts to lag once the number of users at a time gets higher than 200.

It is inefficient for creating small applications, as setting up the Angular 2 development environment is difficult.

Speed It is generally slow. It is many times faster when compared to Angular JS.
Template It has a good template system. It has more powerful templating system than Angular JS.
Syntax It’s syntax is complicated. It’s syntax is simple.
Development Uses controllers and $scope object for development. Uses components and directives for development.
Filters Uses filters to filter out the data. Pipes are used to filter out the data.
Usage It cannot be used for the higher versions of Angular. It has backward compatibility, and can also be used in Angular 4.
Plugin

Additional plugins are not required for the development.

Angular 2 requires additional plugins for development.


Article Tags :