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.

51.

What are UI components in Angular 7?

Answer»
52.

How to set headers for every request in Angular?

Answer»

In order to set headers for every request in ANGULAR 7, HTMLHttpRequest is used. There is a number of benefits such as testability features, TYPES request, request and response interception, observable APIs and streamlined error HANDLING that is associated with, XMLHttpRequest.

Related INTERVIEW QUESTIONS: AngularJS Interview Questions
53.

What are the Core Dependencies of Angular 7?

Answer»

Angular 7 has two CORE DEPENDENCIES namely RxJS and TypeScript

  • RxJS 6.3 – Angular 7 FRAMEWORK uses RxJS version 6.3.
  • TypeScript- Angular 7 framework uses TypeScript version 3.1
54.

What is the difference between structural directive and attribute directive in Angular 7?

Answer»

Structural directive

The main function of the structural directive is to shape and re-shape the HTML LAYOUT, and DOM’s structure. The MODIFICATION and customization of HTML layout are done by ADDING, removing and manipulating the selected HTML elements.

Attribute DIRECTIVES

The attribute directive has its own layout view and styles because it has a single component on a host ELEMENT but it supports multiple directives.

55.

What is a template in Angular7?

Answer»

In Angular 7, templates are written with the help of HTML that contains Angular JS specification elements and ATTRIBUTES. The main role of Angular 7 is to COMBINE the templates which ultimately CONTROL the DYNAMIC view that is visible to the USERS in the browsers.

Related Interview Questions: Angular 4 Interview Questions
56.

What is the UrlSegment Interface in Angular 7?

Answer»

UrlSegment is a modified feature of Angular 7 which is USED to add a new interface. In other words, UrlSegment Interface feature represents URL segment, constructor, properties and methods which are present in UrlSegment CLASS. MOREOVER, UrlSegement is one of the parts of URL, as it contains metric and PATH parameters which are associated and INTERLINKED with the segment.

57.

How to update angular 6 to 7?

Answer»

Steps to update Angular 6 to Angular 7 are

  • Remove deprecated FEATURES and components of RxJS 6 with the help of auto-update RULES from rxjs-tslint.
  • Install the tool by using command npm install –g rxjs-tslin
  • From the root of your project RUN rxjs-5-to 6-migrate –p scr/tsconfig.app.json
  • remove rxjs-compat LIBRARY from rxjs-5-to 6-migrate –p scr/tsconfig.app.json
  • Run command ng update @angular/[email protected]/core

Your Angular version gets updated to V7

58.

What's new in Angular 7?

Answer»

Angular 7 has new and advanced level features such as

  • Modernized v7.0.2 CLI prompts
  • Reflect- METADATA poly-fill part for application performance
  • Angular material and CDK ( COMPONENT Dev Kit)
  • VIRTUAL scrolling PACKAGE
  • Drag and Drop <@angular/cdk/drag-drop>
  • Angular COMPATIBILITY compiler (ngcc)
  • angular Do-bootstrap
  • improved error handling
  • dependency updates etc

In addition to all these features, Angular 7 also provides Documentation updates which include Angular console, @angular/Fire, NativeScript, StackBlitz, and Bazel, platform- browser, etc.

Related Article: What are the new features in Angular 8
59.

What are the difference between angular 6 and angular 7?

Answer»

The main difference between Angular 7 and Angular 6 is -

Differentiable parametersAngular 7Angular 6
FeaturesThe main features that Angular 7 contains are- CLI prompts, Angular Material, Component Dev Kit (CDK), Virtual SCROLLING, and Application Performance Improvements, Angular Material, etc.The main features that Angular 6 contained are- Angular CLI Workspaces, ng update, ng add, Angular ELEMENTS, Animations Performance Improvements, Bazel compiler, service worker safety, etc.
Prime focusAngular 7 primarily focused on upgrading the existing features rather than publishing ADVANCED level features.Angular 6 primarily focused on adding new features and bring new extensible upgrades.
Angular Material and Components Dev Kit (CDK)The Angular 7 framework has minor changes in the IMPROVEMENT of material design.The Angular 6 framework has major changes in the improvement of material design.
Related Interview Questions: Angular 2 Interview Questions
60.

What is angular global APIs?

Answer»

An API stands for Application PROGRAMMING Interface. It is BASICALLY a SET of rules and tools for building software applications. In AngularJS, the Global API is a combination of global functions WRITTEN in Javascript which are used for tasks like comparing/iterating objects or CONVERTING data.

61.

Which command would you use to create a service in Angular 7?

Answer»

The COMMAND, NG generate service [service name] generates a service in Angular.

62.

What are the features of using the AoT compiler?

Answer»

Here are the reasons to USE an AOT compiler in Angular:

  • Faster rendering: Using the AOT compiler, browsers can download a pre-compiled version of the application. This ensures that the browser can render the application immediately using executable CODE without having to wait for the whole compilation.
  • Less asynchronous requests: Using inline external HTML templates and CSS style sheets within the application, the compiler ELIMINATES separate ajax requests for those specific resource files.
  • Reduced Angular framework download size: There's no need to download the Angular compiler if the app is already compiled. This is very advantageous and efficient as the compiler is almost half the size of Angular, so, not having to add that increases the application payload dramatically.
  • Optimized Error Handling: Detecting EXISTING template ERRORS and reporting template binding errors during the building step before users can see.
  • Enhanced Security: Compilation of HTML templates and other components into JS files before client-side rendering. This reduces the scope for risky JS evaluation or injection attacks. The AOT compiler the HTML templates and other components into JS files before they are served to the client. With no templates to read and no risky client-side JavaScript or HTML evaluation, there are fewer opportunities for injection attacks.
63.

What are the router events?

Answer»

In Angular, during each navigation route, the Router sends navigation events through the Router Events property.

Here is the LIST of events range from when the navigation STARTS and ends too MANY points in between.

  • NavigationStart
  • RouteConfigLoadEnd
  • GuardsCheckStart
  • ActivationStart
  • GuardsCheckEnd
  • ResolveStart
  • ActivationEnd
  • NavigationEnd
Example

export class AppComponent {
   constructor(private router: Router) {
   }
   ngOnInit() {
      this.router.events
      .PIPE(filter(event => event instanceof NavigationEnd))
      .subscribe(() => {
         ...
       });
   }
}

64.

What does a router.navigate do?

Answer»

The Router.navigate is USED to specify a root URL through relative navigation. Here’s a function USING the above to navigate through DIFFERENT ARTICLES in Angular:

Example

gotoDetails(articleId: any) {
   this.router.navigate(['/blog/', blogId]);
}

65.

What are the utility functions provided by RxJS?

Answer»

The utility functions PROVIDED by ANGULAR are:

  • map() : Used to map values of different data types
  • filter() : Used for filtering streams
  • concat() : Used to concatenate multiple strings
  • merge(): Used to recursively DESCEND into object properties in the SOURCE copy, while forming a deep copy of the same.
66.

When rendering the page for the first time in Angular, which page is called first?

Answer»

In Angular, the main.ts is the entry point of the application, which runs first when you RENDER a page in Angular. It compiles the application with JIT and bootstraps the Angular application. In Angular 2, you can BOOTSTRAP multiple environments to import a module SPECIFIC to the environment during which angular looks for a specific module to run first.

67.

What is ECMAScript in Angular 2?

Answer»

ECMAScript is a standard of CODING, implemented by JAVASCRIPT. In some browsers, Javascript implements Ecmascript 2015 STANDARDS(also called ES6). It is basically the JavaScript that browsers understand.

68.

What is the purpose of using package.json in Angular?

Answer»

In Angular, the package.json file lets you keep a track of dependencies within a PROJECT. By using the reference of these packages in the dependency section, it enables you to USE a module BUNDLER such as webpack, browserify, etc. The package.json also helps you to keep your project linked to the specific versions of each package if the new version introduces any CHANGES.

69.

What is the difference between property binding and event binding?

Answer» PROPERTY binding

When you have to pass the value from a parent component in ANgular to a child component, we have to use the property binding meaning that by doing so we are sending the value using the ATTRIBUTE on a component and thereby GET the parent using the @Input annotation for the example of property binding LIKE the below example: <my-child [myProp]="prop" />

Event Binding

Caching of Child’s Event/Method using the parent component.

This is used when we have to fire some event on click or maybe something else from the child component while passing it to the Parent.

Here’s an example:

<my-child [myProp]="prop" (onPropChange)="onPropChange($event)"</strong> /> Here, we have user onPropChange as event binding to CATCH and fire an event using EventEmitter.

70.

Which decorator creates services in Angular 2?

Answer»

The injectable DECORATOR in Angular 2 allows the functionality of the creation of a SERVICE to be injected and used in AngularJS modules by defining it as a PROVIDER in the Component Decorator.

Following is a SYNTAX to successfully create a service using the Injectable() decorator

Example

import { Injectable } from '@angular/core';
import { ITEM } from './item';
import { ITEMS } from './mock-items';
@Injectable()
export class ItemService {
   selectedItems: Item[] = [];
   getItems(): Item[] {
   return ITEMS;
}
getSelectedItems(): Item[] {
   return this.selectedItems;
}
addItem(id:number): void {
   let item = ITEMS.find(ob => ob.id === id);
   if (this.selectedItems.indexOf(item) < 0) {
      this.selectedItems.push(item);
   }
}
removeItem(id:number): void {
   let item = this.selectedItems.find(ob => ob.id === id);
   let itemIndex = this.selectedItems.indexOf(item);
   this.selectedItems.splice(itemIndex, 1);
}

71.

What is the Life Cycle Event to check whether the Dom is fully loaded?

Answer»

Modal footer is BASICALLY used when the template is fully loaded. User NEEDS to write the CODE inside the ngAfterViewInit then users will not get the footer element. Thus, footer modal is life cycle EVENT which is used to CHECK whether the Dom is fully loaded or not.

72.

What is internationalization in angular?

Answer»

With application users being across the globe nowadays, Internationalization in Angular is used to SIMPLIFY the PROCESS of DESIGNING and preparing your APP for multiple languages.

73.

What is use of subscribe in Angular 2?

Answer»

The subscribe() function is observable in Angular 2 which defines how to OBTAIN or generate values or messages to be published. To execute a particular observable in a timely fashion, you will have to create NOTIFICATIONS using the subscribe() method.

77. What is entry component in Angular 2?

An entry component in Angular is one that loads imperatively, i.e it can be loaded without any referenced in the template, by any type or CATEGORY. One can specify an entry component by either BOOTSTRAPPING it as a NgModule or even in a routing definition.

74.

What is BASE HREF in Angular 2?

Answer»

The <BASE href="/"> in Angular 2 is to direct the Angular Router to the STATIC PART of a URL. It helps the router to differentiate and make MODIFICATIONS to the URL accordingly.

75.

What is bundling in Angular 2?

Answer»

In Angular 2, Bundling is KNOWN as the process of joining/combining multiple files into ONE single FILE. Third Party-libraries and other dependencies are generally bundled into a module for INCREASING productivity of code.

76.

What is the difference between declarations and entryComponents?

Answer»
DeclarationsentryComponents
USED to make Directives including components and PIPES within a SPECIFIC moduleUsed to register components for offline COMPUTATION in a module
Directives, components, and pipes are matched against the HTML only if they are declared or importedComponents used for router config can be added IMPLICITLY
77.

What is the best IDE for Angular 2?

Answer»

An IDE’s MAIN purpose is to provide a friendly CODING environment. Angular 2 SUPPORTS the following code-editors which are highly efficient:

  • VISUAL STUDIO Code
  • Sublime Text
  • Atom Editor
  • Webstorm
  • Angular IDE
  • ALM IDE
  • Brackets
  • Vim Editor
78.

What is the use of arrow function in Angular 2?

Answer»

They are additionally called lambda features in different languages. Using fats arrow (=&GT;) we drop the want to use the 'function' keyword. Parameters are HANDED in the angular brackets &LT;>, and the characteristic expression is enclosed inside the CURLY brackets {}.

Example

items.forEach((a) => {
    console.log(a);
    incrementedItems.push(a+1);
});

79.

What is HammerJS in Angular 2?

Answer»

It is a famous LIBRARY that helps you add AID for contact gestures (e.g. rotate, swipe, pan, zoom ) to your page. We will enhance a swipe-able card. Angular 2 presents a TOKEN known as HAMMER_GESTURE_CONFIG which ACCEPTS a HammerGestureConfig type.

How to install HammerJS

npm install hammerjs --save

80.

What is gulp in Angular?

Answer»

Gulp is a MISSION runner that APPROVES you to DEFINE a sequence of repeatable tasks that can be run any time you need. You can automate boring matters like the minification and uglification of your javascript or some THING else you do in order to make your CODE production-ready.

81.

How will you deal with angular 2 application errors?

Answer»

The applications in angular 2 have an error handling option which also includes the react JS library to use the catch function. In TURN, the catch function includes a link that sends information about the error handler function. under this function one can send the error as a QUESTION to console file other INSTANCES will send it back in the main program to ensure the CONTINUATION of the OPERATION of the main program. Once it is fixed whenever the error arises it will be redirected in the browser's console.

82.

If the path does not exist how will you redirect it or how you will deal with 404 in Angular 2?

Answer»

USING the angular ROUTING command it GETS easier to navigate through the view page or any other file during any tasks. One can also configure the URL to redirect any other URL and this feature can also be handled to address the PROBLEM of "404 not found". By using the location services one can go back and forward along with the page history. Its syntax is- e can USE {path: '/OUR_PATH', redirectTo: ['redirectPathName']}

This is one of the most common Angular 2 interview questions.

83.

What is the significance of the catalyzer in Angular 2?

Answer»

Codelyzer refers to an open-source tool that is used to run or detect if the predefined coding guidelines are followed or not. It only performs the static code analysis in angular 2 and typescript project because all platforms FOLLOW a SET of easy and conventional coding to maintain it in a better way. Codelyzer also runs on the TOP of tslint where its coding convention is completely DEFINED in the tslint.json file. The DEVELOPER can also run it through an angular click.

84.

What is Activatedroutesnapshot in angular 2?

Answer»

Activatedroutesnapshot in Angular 2 is basically an immutable object which is used to represent a particular version of ActiveRoute.

For the IMPLEMENTATION of Activatedroutesnapshot object FOLLOWING SYNTAX can be used.

export CLASS ActivatedRoute {
   /** The current snapshot of this route **/
   snapshot: ActivatedRouteSnapshot;
}

65. What is Router state in angular 2?

Router state represents all the state of the router as a tree of activated routes.

interface RouterState extends Tree {
   snapshot: RouterStateSnapshot
   toString(): string
}

Also Read: What is the best formal dress for MEN in an interview
85.

What is resolver in angular 2?

Answer»

In actual, resolver (class) is a powerful technique which is USED to achieve the BEST USER experience when browsing between pages in the APPLICATION. For the implementation of the resolver class, it is important to create a new folder called resolves. Thereafter PUT resolvers with same template resolveName.resolver.ts

86.

What is the basic building block of Angular 2?

Answer»

Here is the list of main BUILDING BLOCKS of ANGULAR 2:

  • Modules
  • Dependency injection
  • Data binding
  • Components
  • Templates
  • Directives
  • Metadata
  • Services
87.

What is services and also explain its features in angular 2?

Answer»

Services allow greater separation of CONCERNS in ANGULAR applications. They also provide MODULARITY by allowing developers to extract common functionalities out of components. Adding Services to Angular applications makes components FREE from data access code.

 

Service has the following features:

  • Singleton, i.e. only one instance of service will exist throughout the application.
  • Capable of returning data in the form of Observables and promises.
  • Decorated with @Injectable() DECORATOR
88.

What is decorator in angular 2?

Answer»

Decorators allow developers to configure classes as elements by putting metadata on them.

The most COMMON decorators are @Component one for components and @INJECTABLE one for classes.

Decorators are new in TYPESCRIPT, and were not AVAILABLE in AngularJS. Angular2 ONWARDS offers four types of decorators and each plays a unique role - Class, Property, Method, and Parameter.

89.

What is the difference between ng-model and ng-bind in AngularJs?

Answer»
Ng modelNg bind
This works as a two-way data BINDING where the user has to bind a variable to the field and output the same variable wherever the user desire to DISPLAY that UPDATED value anywhere in the application.
The SYNTAX used for ng-model is –
<textarea ng-model="propertyName"></textarea>
It's a one-way data-binding used by DEVELOPERS for displaying the value inside HTML component as inner HTML.
The syntax used for ng-bind is –
<div ng-bind="propertyName"></div>
90.

What are the security threats should we be aware of in angular 2?

Answer»
  • AVOID INJECTING dynamic Html content
  • Sanitize external HTML
  • Do not PUT external URLs in the application
  • Use AOT compilation
  • Prevent XSRF attack by RESTRICTING API
91.

What are the life cycle hooks order in AngularJS?

Answer»

This below MENTIONED will be the LIFECYCLE HOOKS ORDER in AngularJS.

  • ngOnChanges()
  • NGONINIT()
  • ngDoCheck()
  • ngAfterContentInit()
  • ngAfterContentChecked()
  • ngAfterViewInit()
  • ngAfterViewChecked()
  • ngOnDestroy()
92.

What technique uses Angular 2 for two way binding?

Answer»

In GENERAL, two-way data BINDING in ANGULAR 2 is the AUTOMATIC synchronization of data between the view components and model. Two-way data binding allows the users to treat the model as a single SOURCE of truth in your application.

93.

What are observables in angular 2? Explain

Answer»

An observable is an array where data arrives asynchronously.

Observables can help DEVELOPERS manage ASYNCHRONOUS data and are used within Angular, including event SYSTEM and HTTP client service. Angular uses REACTIVE Extensions (RxJS), a third-party library, to use Observables.

94.

What is difference between rootScope and scope in Angular 2?

Answer»

rootScope

It's an AngularJS SERVICE that implements the underlying EVENT and state management mechanism for AngularJS ATTRIBUTES, DIRECTIVES, views and controllers.

Scope

Whereas, it's a conventional parameter name given to a directive's link function's first ARGUMENT.

95.

What is rootScope in angular 2?

Answer» AVAILABLE with all Angular applications, rootScope is the SCOPE HTML element created scope which contains ng-app directive. It is available in the ENTIRE application.
96.

What do you mean by module in angular 2?

Answer»

In Angular 2, a MODULE groups the various components, pipes, directives, and services in a WAY that assists them in combining with other MODULES for creating an application.

A module can be USED to hide or export pipes, directives, components and services.

97.

What are promises in angular 2?

Answer»

Promises in Angular 2 execute asynchronous functions in SERIAL ORDER by registering promise OBJECT. Additionally, promises are PROVIDED by build-in $q service. Promises have generated a new way into native JavaScript as a part of the ES6 SPECIFICATION

98.

What is the difference between a service() and a factory()?

Answer»
factory()service()
The factory function allows developers to add certain logic before the creation of an object.This one is a constructor function which helps creating the object with a new keyword. Developers can add functions and properties to a service object by using the keyword.
It will RETURN the created object.It returns nothing.
Syntax:app.factory('serviceName',function(){ return serviceObj;}Syntax:app.service('serviceName',function(){})
50. What is the difference between Angular 2 and AngularJS?
 AngularJSAngular 2
1.No mobile supportMobile-oriented
2.Only supports Dart, ES6 and ES5Offer more language choices
3.Easy to SET upDependent on libraries. REQUIRES efforts to set up.
4.Based on controllers and scopeComponent-based.
Also Read: AngularJS VS. Angular 2 vs. Angular 4: What's the Difference
99.

What is the use of codelyzer in angular 2?

Answer»

It is an open source TOOL for running and CHECKING if the pre-defined CODING GUIDELINES were followed or not. It does static code analysis for typescript and angular projects.

It runs on top of tslint and coding conventions are defined in tslint.json file. Editors such as Visual Studio Code SUPPORT codelyzer by doing basic settings.

100.

How to redirect to 404 or other path if the path does not exist in Angular 2?

Answer»

Using angular routing you can NAVIGATE from one view or page to another while performing your tasks. You can configure a URL to redirect to the next URL. This feature can be handled to ADDRESS the "404 Not FOUND" problem. Using location services in Angular routing you can go back and forward through the history of pages.

Syntax : We can use {PATH: '/OUR_PATH', redirectTo: ['redirectPathName']}

Example

{path: '/404', NAME: 'PageNotFound', component: NotFoundComponent}