Home / Question / Angular 2 Questions and answer for preparing interview
Angular 2

Angular 2 Questions and answer for preparing interview

Angular 2 is an open source JavaScript framework to build web applications in HTML and JavaScript and has been conceived as a mobile first approach.

  1. What is Angular 2 ?
  • Angular 2 is a JavaScript framework for developing single page applications by following MVC based architecture.
  • Angular 2 follows modular approach/architecture.
  • It supports 1 way, 2 way databinding.
  • It helps in reusability as we creates lots of modules & components.
  1. How Angular 2 is different than Angular 1 ?
  • Angular 1 comes with default 2 way data binding which makes it slower as compared to Angular 2.
  • Angular 2 modular design makes use of re usability more as compared to Angular 1.
  • Angular 2 works with Typescript which provides OOPS features.
  1. What is Type Script ?
  • It is Superset of JavaScript, built on top of JavaScript.
  • It provides supports for Strong Typed variables.
  • We can implements interfaces, classes & generics in typescript.

Var num: number = 5;
Var name:string = “sample”;
Var object:any = 123;
Var personObj:any = {Name:”A”, Age:25};
Var list:Array<string> = [“A”,”B”,”C”];

  1. What are directives ?
  • Directives are nothing but the instructions living in the HTML that’s tells Angular 2 to transform a piece of code into an expected action to get the data.
  • Types of directives are Attribute, Structural, Element & Custom directive.
  1. What is Structural, Attribute, Element & Custom directive in Angular 2 ?
  • Structural Directives:
    • The directive which defines/changes the structure of HTML element on which it tagged.
    • It can change the appearance or behavior of an element.
    • *ngIf, *ngFor & [ngSwitch] are example of it.
  • <div [ngSwitch]=’red’>
    • <div [ngSwitchWhen]=”‘red'”>
      • <div *ngFor=’#x of Xlist’>
        • <div *ngIf=’1==1′> Show me</div>
      • </div>
    • </div>
  • </div>
  • Attribute Directive
    • Attribute directives are those which helps us define some properties to the HTML element. For example [ngClass], [ngStyle] is such an attribute directive.
  • Element Directives
    • Directives which are defined on the HTML element attributes like hidden, disabled, class etc.
  1. What is component ?
  • Components are directives which do not live in HTML elements in fact they are like HTML elements specified by the selector name given to them.
  • Components are the special directives with a view attached to them.

@component ({

selector: ‘my-selector’,

template: ‘app-component.html’,

directives: [],

providers: [],

input: [],

output: []


  1. What is selector ?
    • Selectors are nothing but a name given to a component as an alias to use component in an HTML file.
    • Selector is like the custom html tag which is used to let Angular 2 to know that it has to include the html template at particular location on Html page.
  1. What are services ?
  • Services are the Key element in Angular 2 application holding certain data information / functionality that is present in the centralized place that can be used through application.
  1. What is Templates or Template URL ?
  • Templates or template URL is the element in the component declaration block.
  • Using “template” we can define the html block which is used to show HTML data on browser.
  • Using “TemplateURL”
  1. What are types of Data-binding in Angular 2 ? How Angular 2 handles data-binding?
    1. String interpolation ({{}}).
    2. Property / directive binding.
    3. Event Binding.
    4. 2 way data binding (“[()]“).
  1. What are providers ?
  • Providers are nothing but a class or function or services which provides a result set to a component on which it is being used.
  • If class provider is used them the instance of the class will be a result for the component.
  1. What are Input & Output in Angular 2?
  • @Input is used to send data to the component dynamically as a property to the component.
  • @Output decorator is used to send out the data out of the component to the parent component. Using @Output decorator data is emitted out.
  1. What are Angular 2 Events ?
  • Angular 2 events are nothing but a parenthesis notation in templates. Using the parenthesis we can trigger method of the component class. The events are the DOM events which we specify of HTML elements e.g. click, mouseenter, mouseout.
  1. What is @ViewChild does in Angular 2 ? How to use it? When to use it?
  • @ViewChild is a decorator to view the child element of the Component template. Using @ViewChild we can view HTML element or another Component.
  1. What is Event Emitter in Angular 2?
  • Event emitter is used with the @Output decorator to emit the value out of the component.
  1. Does ngModel updates if the html is updated explicitly ?
  • Yes, ngModel updates the model attached to it when there are changes made in the HTML explicitly.
  1. What is Dependency injection ?
  • It is a coding pattern in which we inject dependency in the class so that while using the class, external class/source will pass the required data/dependency rather than we create it for them.
  1. Life Cycle of Component (reference Angular LifeCycle Hooks)

angular_2_question_answer Angular 2 Questions and answer for preparing interview Question Web

About Helpservices

About This site (allhelpservices.com) is dedicated to helping other bloggers learn the skills of blogging, wordpress, education, technology, social media sharing , SEO, Electronics, Earn Money From Blogging, Web hosting and web share their own experiences and promote the blogging medium. We started Allhelpservices in August 2015 mainly because we wanted to keep a record of what we wear learning from development and because we wanted to connect with other learners.

Check Also

style sheet

What are ways of inserting a style sheet?

Cascading Style Sheets (CSS) describe how documents are presented on screens, in print, or perhaps ...

Leave a Reply