Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

101.

What is routing in angular 2?

Answer»

Routing is what lets in you to create Single Page APPLICATIONS. AngularJS routes ALLOW you to create distinct URLS for ONE of a kind content material in your application. It helps in redirecting users to exceptional pages based totally on the alternative they pick out on the main page. AngularJS routes ENABLE one to show more than one content depending on which route is chosen. A route is unique in the URL after the # sign.

Related Article: How to Overcome the Fear of Angular 2 Interview Questions
102.

What is the factory method in Angular 2?

Answer»

As services are reusable singleton objects in AngularJS which is USED to organize and share CODES across the APPLICATION, they can be injected into filters, controllers, and directives. Angular 2 offers three ways to create a service; factory, service, and provider.

The factory function allows developers to include some logic before creating the object and RETURNS the created object. The syntax for factory function is as follows.

app.factory('serviceName',function(){ return serviceObj;})

103.

What is deep linking in Angular 2?

Answer»

In Angular 2, deep linking is a process of the URL that will take to users to a SPECIFIC page or content DIRECTLY without crossing the application from the homepage. The deep linking process helps with website or application indexing so that search engines can EASILY crawl these links.

104.

What happens when the page containing Angular based application loads?

Answer»

When a page containing Angular BASED application loads, these below-mentioned scenarios will be completed.

  • The browser will load the HTML DOCUMENT and evaluate it.
  • The file for AngularJS JavaScript will be LOADED and the Angular global OBJECT will be created.
  • Finally, the JavaScript that registers controller function will be executed.
105.

What is Angular 2 and also explain its components?

Answer»

Angular 2 is the UPGRADED and evolved version of AngularJS, a JavaScript FRAMEWORK that was INVENTED by Google. Angular 2 is used for building single-page web or mobile applications.

Components are essential elements of Angular 2 apps, and an application can have a number of components. In Angular 2, components PERFORM all the tasks that were done by scopes, controllers and directives, such as creating or adding Data, logic, and CUSTOM elements.

In Angular 2 a component consists of the following:
  • Template
  • Class
  • Metadata
106.

What are lifecycle hooks and why it is important?

Answer»

In ANGULAR, lifecycle hooks are FUNCTIONS which will be called at specific POINTS of a component lifecycle in Angular applications.

They are HIGHLY crucial for a component architecture based application.

107.

What is the use of polyfills.ts file in Angular 2?

Answer»

In Angular 2, the polyfills.ts file is used to MAKE user application compatible for VARIOUS browsers. The code we write in Angular 2 is mostly in ES6, which is not compatible with FIREFOX or IE, and requires few environmental setups before they wither get VIEWED or used in browsers.

Angular offers Polyfills.ts file to help users with the required setup.

108.

What is the difference between annotation and decorator in Angular 2?

Answer»
AnnotationDecorator
Used by Traceur compilerUsed by Typescript compiler
Annotation creates the attribute ‘ANNOTATIONS’ that stores arrays and PASS metadata to the constructor of the annotated class.It is a function that GETS the object that needs to be decorated (or constructed). They can change the attributes of the object as necessary.
Annotations are hard-codedNot hard-coded
EXAMPLE – import {COMPONENT} from 'angular2/angular2';Example - import {ComponentAnnotation as Component} from 'angular2/angular2';
109.

How to create a singleton service in Angular 2?

Answer»

Here is the steps to CREATE a singleton service-

  • Import the injectable member using import {Injectable} from '@angular/core';
  • Import the HttpModule, HTTP and Response members’ as import { HttpModule, Http, Response } from '@angular/http';
  • Add the decorator @Injectable()
  • EXPORT
    export class UserService {
       constructor(private _http: Http) { }
    }
ALSO Read: How to negotiate a higher SALARY after a job offer
110.

How you can load external css style?

Answer»

To ALLOW a load of external CSS styles in Angular 2 to affect component contents, we have to change view ENCAPSULATION which presents styles to COMPONENTS referring “bleed into”.

@Component({
   selector: 'some-component',
   template: '&LT;div&GT;</div>',
   styleUrls: [
      'https://bestinterviewquestion.com/style.css',
      'app/local.css'
   ],
   encapsulation: ViewEncapsulation.None,
})
export class SomeComponent {}

111.

What is shadow dom and how it is helping to perform better in angular 2?

Answer»

Shadow DOM is an integral PART of Web Components standard while enables users for style ENCAPSULATION and DOM tree. It helps users to hide DOM logic behind other elements. With the addition to it, we can also APPLY scoped styles to elements WITHOUT showcasing them to the outer world.

112.

How to define custom typings to avoid editor warnings?

Answer»

To avoid editor warning whilst defining CUSTOMIZED typings, we have to prolong the KIND DEFINITION for an external library as a accurate practice. Without ALTERING any node_modules or current typings FOLDER, we have to create a new folder named “custom_typings" and put all our customized kind definitions there.

113.

What is tree shaking?

Answer»

The Tree SHAKING is a concept of dead code elimination from PROJECTS. The code PRESENT in your project but neither referenced nor USED will be dropped here. It will eliminate the unused modules during the BUILD process, making user application lightweight.

114.

What is the purpose of tsconfig.json in Angularjs?

Answer»

It allows us to specify the root level files. The compiler options required to compile a TypeScript project. It DETERMINES that the said DIRECTORY is the TypeScript project root. Here is a JSON file describing to define a tsconfig.json file containing different parameters of the compilerOptions property:

{

    "compilerOptions": {
    "noImplicitAny": true,
    "module": "system",
    "removeComments": true,
    "strictNullChecks": true,
    "sourceMap": true,
    "allowUnreachableCode": false,
    "outFile": "../JS/TypeScript/BestInterviewQuestion.js"
  }
}

Here is an example of these options.
  • target: It is used for the compiled OUTPUT.
  • module: It is used in the compiled output. the system is for SystemJS, common for CommonJS.
  • moduleResolution: It is used to resolve module declaration files (.d.ts files). With the NODE approach, they are loaded from the node_modules.
  • sourceMap: generate or not SOURCE map files to debug your application.
  • emitDecoratorMetadata: emitDecoratorMetadata emit or not design-type metadata for decorated declarations in the source.
  • experimentalDecorators: It enables or not experimental support for ES7 decorators,
  • removeComments: remove comments or not
  • noImplicitAny: It is used to allow or not the use of variables.
115.

Is angular 2 Object Oriented?

Answer»

Yes, Angular 2 is a TRUE object-oriented development framework.

116.

How would you optimize the application for better performance in angular 2?

Answer»

To optimize an application for optimal performance in Angular 2, we have to follow the below-mentioned steps.

  • USE of AOT compilation.
  • With a large-size app, use lazy loading instead of the FULLY bundled app.
  • Avoid un-necessary import STATEMENTS in the application.
  • Remove unused and unnecessary 3rd party libraries from the application.
  • If not required, consider REMOVING application dependencies.
117.

What is primeng and how can it be used with angular2?

Answer»

PrimeNG is a rich UI component collection DEDICATED to ANGULAR. Widgets present here are completely open-source and FREE to use. It’s simple, lightweight yet powerful and optimized for RESPONSIVE cross-browser touch.

118.

What is SPA in Angular 2?

Answer»

SPA in Angular 2 stands for Single Page Applications. This is a TYPE of web-application which fits into literally one page. All your code (JavaScript, HTML, CSS) is CALLED using a single page load at multiple points by adding new data parallelly from the backend. Navigation between pages PERFORMED can be DONE without refreshing.

119.

What is Flex layout in Angular 2?

Answer»

Flex Layout in Angular 2 is a component engine that allows you to CREATE Flexbox page layouts with a fixed SET of directives to use in designing templates. The Flex-Layout has made styling EASY and user-friendly by having a TypeScript based Library, thus eliminating the need for external stylesheets/CSS Styling. In addition to this, it can be used along with Material Design for Design components and also providing intuitive BREAKPOINTS while development to AID in designing responsive layouts.

120.

How to display the error message from backend in angular2?

Answer»

To DISPLAY error message in Angular 2 from BACKEND, we have to set the error message equal to an angular variable, and then check whether that variable exists to CONFORM whether to display it or not.

<div *NGIF="errors" class="alert alert-danger">
    {{ errors }}
</div>

 

121.

What is @input and @output in Angular 2?

Answer»

Both @input and @output are decorators. The decorator @Input is used to bind a property WITHIN ONE child COMPONENT to receive value from the parent component, WHEREAS we use the @output decorator to bind the property of a component to send data from child component to parent component or calling component.

122.

What is hidden property in Angular 2?

Answer»

In Angular 2, hidden property or [hidden] is a special case binding USED to hide property. It can be compared CLOSE to ng-show and ng-hide, but more powerful to bind any property types of elements.

Example &LT;div [hidden]="!active"> Hello, this is an active AREA! </div>
123.

What are filters in Angular 2?

Answer»

A filter is a NECESSARY phase of Angular 2 as well as Angular 4. It is basically used to filter an object from a crew of items, which are there in an array or an object array. It SELECTS a subset of the objects from an array and returns it as a new array and displayed on UI. Filters can be used with an expression USING pipe | sign. {{expression | filterName:parameter }} Angular 2 includes various filters to layout records of special fact types.

Also Read: How to crack the interview in the first ATTEMPT
124.

What is Router-link directive in Angular 2?

Answer»

The router-link derivatives enable the navigation from any specific view to the other. It works immediately as a USER is performing application tasks. The link can directly arise from browser and navigation is done on the basis of user action like the click of an anchor TAG.

The router link directive gives control to the router for anchor tag elements. It also binds a clickable HTML to the route to enable the navigation. The routerlink directive can easily be bound to an array, E.g.

<a [routerlink] = "[ '/ heroes']" >Heroes</a>

23. What is the configuration required for caching of static resources like IMAGES, css and js in Angular 2?

During Development MODE, caching for static resources can be done through the Design of Tools. If you want to cache on the production stage, you need to CHECK and update the Server-End Settings accordingly.

Note: These are basic angular 2 interview questions that are asked for a position as SDE in Angular Development.

125.

How do you check if angular CLI is installed?

Answer»

To CHECK this, you need to make SURE that node is INSTALLED and then check if angular CLI is installed.

  • Open a command prompt using cmd.
  • Type node -v and npm -v to ensure node is installed.
  • Type ng -v
126.

What are the advantages & limitation of AOT compilation?

Answer»

Advantages-

  • Fast download
  • Quicker rendering
  • Reduces Http Requests
  • Catches errors during the build phase
Disadvantages-
  • Only works with HTML and CSS Not other file types.
  • Must MAINTAIN bootstrap file AOT version
  • Must clean-up before COMPILING.
127.

What is AOT compilation?

Answer»

The AOT COMPILATION converts Angular HTML and TypeScript codes into JavaScript code at some stage in the construct section earlier than the browser can down load and RUN the code.

Here are benefits of compiling with AOT:

  • Lesser asynchronous requests
  • Smaller download size of Angular framework
  • Detects errors easily
  • Fast rendering
  • Improved security
Related Article: TOP 10 FREQUENTLY Asked Interview Questions of Angular 2
128.

What are the difference between @injectable() vs. @inject() in angular 2?

Answer»
 @INJECTABLE@Inject
1.Aims to SET metadata of dependencies to be injected into constructorTells Angular what PARAMETER must be injected
2.Without it, no DEPENDENCY can be injectedOnly NEEDED to inject primitives
129.

What is CLI in Angular 2?

Answer»

It is a command-line interface which is USED to build angular apps. We can construct & START a project very QUICKLY with the help of CLI.

You can download CLI from its official website HTTPS://cli.angular.io

The command for INSTALL Angular CLI

npm install –g angular-cli

Also Read: Front end Developer Interview Questions
130.

Explain the steps for creating a services in Angular 2?

Answer»

Here are the steps:

 

Here is the SYNTAX:

import { Injectable } from '@angular/core';
   @Injectable()
   export class MyCustomService {
}

131.

What are angular 2 hooks?

Answer»

In Angular apps, hooks are FUNCTIONS that are called on particular stages of a component’s life. Hooks are ESSENTIAL if your APP is based on the component ARCHITECTURE. Example for hooks is $onInit, $onChanges, etc. which are properties pre-defined by Angular and can be exposed on component controllers.

132.

What are the advantages of Angular 2 over Angular?

Answer»

Advantages of Angular 2 over Angular are given below-

  • Simpler to Learn
  • Simpler Dependency Injection
  • It’s is a platform not only a language:
  • IMPROVED Speed and Performance: No $Scope in Angular 2, AOT
  • Modular, cross-platform
  • Flexible Routing with Lazy Loading Features
  • Benefits of ES6 and Typescript.
14. How do observables differ from promises?
 ObservablePromise
1.USED from the library RxJS.
import { Observable } from 'rxjs';
Built-in API.
2.Can show multiple values using setInterval() methodCan resolve only ONE async task and cannot be used again
3.Can unsubscribe from the observables no LONGER needed.A promise cannot be canceled.
4.Lazy. Observable is called only when we subscribe.Not lazy.
5.Rich set of operators in the library like map, filter, pipe, RETRY, etc.No such additional features available
133.

How do you declare a global variable in Angular 2?

Answer»

The SIMPLEST WAY is to put the variables in a file and export them. In order to USE global variables, you can use an import statement.

'use STRICT';

export const name='bestinterviewquestion.com';

After that, we can export this file where we want to use these global variables value.
import * as myGlobalsFile from './globalfile';

134.

What is lazy loading in angular 2?

Answer»

Lazy loading allows developers to load different code pieces on demand. For instance, if you have a retail APPLICATION that has different departments like garments, groceries, electronics, etc. If you load all the sections, in the beginning, your application will be slow. This is when you need lazy loading. It helps the application load faster because it LOADS only PARTS that the USER wants to see.

This interview questions on angular 2 are always a level up and thus a little tough to crack.

Related Article: What is lazy loading in angular 2
135.

How to enable lazy loading in Angularjs?

Answer»

With lazy LOADING, JS components can be LOADED asynchronously on activation on a specific route.

  • Download and INSTALL ocLazyLoad.js
  • Add the module in the application
  • Load the file in the required controller
  • Add to the router’s code as
Example

resolve: {
     loadMyCtrl: ['$ocLazyLoad', function($ocLazyLoad) {return $ocLazyLoad.load('routerState');
}]}

136.

What is pipes in Angular 2?

Answer»

In all ANGULAR version from 2 onwards, there is a common feature called Pipes. This feature helps developers create custom pipes.

Pipes are used to write display-value transformations that developers can declare in their HTML. A pipe INPUTS data and TRANSFORMS it into the REQUIRED output.

Pipes in Angular2

There are some pipe provided by angularjs are given below-

  • Uppercase/Lowercase Pipe
  • Date Pipe
  • Currency Pipe
  • JSON Pipe
  • Async Pipe
137.

What is dependency injection in Angular?

Answer»

Angular has a robust DI FRAMEWORK that gives declared DEPENDENCIES to a class upon instantiation. To inject a SERVICE, you must first create and register the injectable service.

Related Article: Angular 8 interview questions and AnswersExample

import { Injectable } from '@angular/core';
@Injectable({ providedIn: 'root', })
export class SampleService { constructor() { } }

138.

What is RouterOutlet in Angular 2?

Answer»

In ANGULAR 2, the RouterOutlet is a directive PRESENT in the ROUTER library to be used as a component. It marks the spot in a template for the router to DISPLAY the components for that outlet.

Every outlet can have its unique name, which is determined by the optional name ATTRIBUTE. The name once set cannot be changed dynamically. If no value has been set, the default value is "primary".

<router-outlet></router-outlet>

<router-outlet name="left"></router-outlet>

<router-outlet name="right"></router-outlet>

The router outlet emits an activate event during the instantiation of a new component. When the component is destroyed, it is deactivated.

<router-outlet (activate)='onActivate($event)' (deactivate)='onDeactivate($event)'></router-outlet>

139.

What is directive in Angular?

Answer»

DIRECTIVES are the extended HTML attributes and they are ALSO the most IMPORTANT FEATURES of Angular applications. They introduce syntax or markup.

There are 3 kinds of directives-
  • Components
  • Structural
  • Attribute
140.

How do you create a custom pipe in Angular?

Answer»

In Angular 2, you can create CUSTOM PIPES. The simplest way is as follows.

import { Pipe, PipeTransform } from '@angular/core';
    @Pipe({name: 'Pipename'})
    EXPORT class Pipeclass implements PipeTransform {
    transform(PARAMETERS): returntype { }
}

141.

What is string interpolation Angular?

Answer»

String Interpolation is a SPECIAL syntax in Angular 2 which is a more efficient alternative to property binding. It is used to display dynamic data on an HTML TEMPLATE while facilitating you to make changes on the component.ts FILE and fetch data for the HTML template.

Below is an example of a String Interpolation syntax. It should be between double curly braces {{ }} and hence also CALLED a moustache syntax:

Example

class AppComponent
{
    propertyName: string;
    object: DomainObject;
}
{{ propertyName }}
{{ object.propertyName }}

142.

What is event emitters in Angular 2 and how it works?

Answer»

Any change that occurs in the component gets propagated from the existing component to its children. If this change NEEDS to be reflected its parent component, you can use USING Event Emitter api to emit the event.

EventEmitter is class in @angular/core module that is used by DIRECTIVES and components to emit events.

@output() somethingChanged = new EventEmitter();

You can use somethingChanged.emit(VALUE) to emit any event. You can do this in setter when the value is changed in the class.

143.

What is Traceur compiler in Angular 2?

Answer»

Traceur compiler takes classes, GENERATORS, and other FEATURES from ECMAScript edition 6 (ES6) and compiles it into JavaScript ES5 that runs on the browser. This means developers can use the code from a FUTURE version that has more features and encourages design patterns.

144.

What is the difference between directive and component in Angular 2?

Answer»
 ComponentsDirective
1.To REGISTER, USE @Component meta-data annotationTo register, use @Directive meta-data annotation
2.Used to create UI widgets and break up app into smaller componentsUse to design re-usable components and add behavior to EXISTING DOM element.
3.Only one component allowed per DOM elementMany DIRECTIVES allowed per DOM element.
4.@VIEW decorator is mandatoryDoes not use View.
Also Read: Angular 6 Question and Answers
145.

What is the difference between component and directive in Angular 6?

Answer»
ComponentDIRECTIVE
A component is a directive used to SHADOW DOM to create and encapsulate visual behavior called components. They are typically used to create UI widgets.A Directive is usually used while adding behavior to an existing DOM element.
For registering a component, we use @Component metadata annotation attributes.For registering directives, we use the @Directive meta-data annotation attribute.
It is also used to break up the APPLICATION into smaller components.It is mainly used to DESIGN re-usable components.
Only one component is allowed to be present per DOM element.Multiple directives can be used in a per DOM element.
@View decorator or TEMPLATE URL template is mandatory in a component.A Directive does not have View
A component is used to define pipes.You can’t define Pipes in a directive.
146.

What is a dl token in Angular 6?

Answer»

In Angular 6, a DI TOKEN means a Dependency Injection Token. It is basically a lookup token associated with a dependency provider, to be USED in the Dependency Injection SYSTEM.

147.

What are the case types in Angular 6?

Answer»

There are three CASE types in ANGULAR 6:

  • UPPER case Pipe
  • Lower Case Pipe
  • Title Case Pipe
148.

What is HostListener in Angular?

Answer»

HostListener in Angular 6 is basically a decorator which declares a DOM EVENT to LISTEN for and also provide a handler method to run if and when that specific event OCCURS. Host Listener is a SET of arguments that is USED to pass the handler method when an event occurs.

149.

What is style function in Angular 6?

Answer»

In Angular 6, a style FUNCTION is USED to declare a key or VALUABLE object which contains CSS properties and or styles that shall be used in an animation state or sequence. It can be used within styling data for calls to ANIMATE and keyframes.

150.

What is Linting in Angular?

Answer»

In Angular 6, LINTING is a tool that is used to check the TYPESCRIPT code for programmatic and styling ERRORS. A JSON FILE is a CONFIGURATION for linting and this file contains all the default guidelines for linting.