angular2 and angular4 interview questions and answers part1

1) What is Angular 2 ? 

    Angular 2 is released in the year 2016,Angular 2 is completely rewritten, so it has lot of improvements when compared with Angular 1.
    From a performance standpoint, Angular 2 has faster and the other hand is designed from the ground up with mobile support.
    In Angular 2, "everything is a component". Components are the building blocks of an Angular application.

2) What is Type Script ?

    TypeScript is a free and open-source programming language developed by Microsoft. It is a superset of JavaScript and compiles to JavaScript through a process     called transpilation

3) What is the default port number to run(in local) angular 2 application in browser ?


4) What are the softwares need to install for angular 2 ?

    install Node.js and npm. It is recommended that you have node version 4.6.x or greater and npm 3.x.x or greater

5) What are the commands to check Node and Npm versions using command prompt ?

    C:\Users\user>npm -v
      Output : 5.5.1

    C:\Users\user>node -v
      Output : v8.9.3

6) How to Install the Angular CLI using command prompt ?

   > npm install -g @angular/cli

7) How to create a new Angular 2 application using command prompt ?

    > ng new angular My-Sample-App

8) How to launch the Angular 2 application using command prompt ?

   > cd angular My-Sample-App
   > ng serve --open

9) How to create a new component in angular 2 application using command prompt ?

   > ng generate component My-First-Component

10) How to create a new service in angular 2 application using command prompt ?

   > ng generate service My-First-Service

11) How to create a Module in angular 2 application using command prompt ?

    > ng g module My-First-Module

12) How to create a Directive in angular 2 application using command prompt ?

   > ng g directive my-new-directive

13) How to update Angular CLI old version to a new version ?

   you must update both the global package and your project's local package.

   Global package:

   > npm uninstall -g @angular/cli
   > npm cache verify

   > npm install -g @angular/cli@latest

    Local project package:

   > rm -rf node_modules dist # use rmdir /S/Q node_modules dist in Windows Command Prompt; use rm -r -fo node_modules,dist in Windows PowerShell
   > npm install --save-dev @angular/cli@latest
   > npm install

14) What are the supported Editors in TypeScript ?

    1. Visual Studio Code
    2. Eclipse
    3. WebStorm
    4. Atom
    5. Sublime Text

15) Can we learn AngularJS 1 before learning Angular 2 ?

     No. You can think of AngularJS 1 and Angular 2 as 2 different frameworks. The concepts, the API's and patterns that we use to build applications are very      different between these 2 versions. So there is no need to learn AngularJS 1 before you learn Angular 2

16) Can we learn Angular 2 before learning Angular 4 ?

     Yes,Building an application using Angular 2 and Angular 4 is not very different. We still use the same concepts, APIs and patterns.

17) What is the difference between AngularJS and Angular 2 ?

    AngularJS and was released in the year 2010
    AngularJS applications around the concept of controllers,View and $scope in AngularJS
    AngularJs is 5 times  slow compared to Angular 2.
    AngularJS was not built for mobile devices
    AngularJS no more language choices,no TypeScript used

    Angular 2 is released in the year 2016
    Angular 2 both controllers and $scope are gone,Angular 2 is entirely component based, which means we create a set of independent or loosely coupled components
    Angular 2 is 5 times faster compared to AngularJS.
    AngularJS was built for mobile devices
    Angular 2 we have more language choices. In additon to nativa JavaScript we can use TypeScript, Dart, PureScript, Elm, etc

18) What is a component in Angular 2 ?

    A component in Angular is a class with a template and a decorator. So in simple terms a component in Angular is composed of these 3 things

    Template - Defines the user interface. Contains the HTML, directives and bindings.

    Class - Contains the code required for template. Just like a class in any object oriented programming language like C# or Java, a class in angular can contain     methods and properties. Properties contain the data that we want to display in the view template and methods contain the logic for the view. We use TypeScript to     create the class.

    Decorator - We use the Component decorator provided by Angular to add metadata to the class. A class becomes an Angular component, when it is decorated with the     Component decorator.

19) What are the differences between template and templateUrl properties and when to use one over the other ?

    Angular2 recommends to extract templates into a separate file, if the view template is longer than 3 lines. Let's understand why is it better to extract a view     template into a seprate file, if it is longer than 3 lines.

     With an inline template 

    We loose Visual Studio editor intellisense, code-completion and formatting features.
    TypeScript code is not easier to read and understand when it is mixed with the inline template HTML.

    With an external view template

   We have Visual Studio editor intellisense, code-completion and formatting features and
   Not only the code in "app.component.ts" is clean, it is also easier to read and understand

20) What is AppModule ?

    AppModule is the root module which bootstraps and launches the angular application. You can name it anything you want, but by convention it is named AppModule.

     It imports 2 system modules - BrowserModule and NgModule

    BrowserModule - Every application that runs in a browser needs this module. In a later video in this course we will discuss NgIf and NgFor directives which are     also provided by this module.

    NgModule - @component decorator adds metadata to an angular component class, similarly @NgModule decorator adds metadata to the angular module class

21) How to Error Handle in angular2.0 ?

    private handleError(error: Response) {
        return Observable.throw(error.json().error());

About Author: author 4 + years of Information Technology experience in understanding and analyzing the software and hardware engineering requirements, onsite and offshore management of product development. Expert work on design and development for windows,web,mobile Expert knowledge of C#,ADO.NET, ASP.Net MVC, ENTITY FRAMEWORK, LINQ,COLLECTIONS, JAVASCRIPT,AngularJs 1.0,Angular2, Jquery,Jquery-Ajax, SQL SERVER, XAML,Windows phone 8.1 Good knowledge of WCF-Restful services,WCF, WEB API-Services ,Web- Services,MIcrosoft-Azure,JUICE UI,HTML,CSS,AJAX Read More...

Join him on Google+ | Facebook | Linkedin


  1. Hats off to your presence of mind..I really enjoyed reading your blog. I really appreciate your information which you shared with us.
    Angularjs course in chennai