Angular 7 Interview Questions

Best Angular 8/7/6/5/4/3/2 Interview Questions (Frequently Asked)


A list of top frequently asked Angular 7 Interview Questions and answers are given below.

1) What is Angular 7? How is it different from AngularJS?

Angular7 is the latest and recent version of Angular. AngularJS was the first version of Angular which is also known as Angular 1.0.
Angular7 is the complete rewrite of the Angular1.0. It supports two-way data binding, and some other features like ng update, ng add, Angular Elements, Angular Material + CDK Components, Angular Material Starter Components, CLI Workspaces, Library Support, Tree Shakable Providers, Animations Performance Improvements, and RxJS v6 etc.

2) What is Angular framework?

Angular is a TypeScript-based open-source web framework and a platform. It is used to build web/ mobile and desktop applications.
Main features of this framework are: Declarative templates, dependency injection, end to end tooling etc. These features make web development easy in Angular.

3) What is the difference between AngularJS and Angular?

Angular is a complete rewrite of AngularJS. It is a component-based framework in which an application is a tree of individual components.
Difference between AngularJS and Angular:
AngularJSAngular
AngularJS is based on MVC architecture.Angular is based on Service/Controller.
It uses JavaScript to build the application.It uses TypeScript to build the application.
It follows controller concept.It follows Component based UI approach.
It is not a mobile-friendly framework.It is a mobile friendly framework.
It is very difficult to create a SEO friendly application in AngularJS.By using Angular, you can easily create a SEO friendly application.

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

Structural directives are used to alter the DOM layout by removing and adding DOM elements. These directives are far better in changing the structure of the view. Examples of Structural directives are NgFor and Nglf.
Attribute Directives are used as characteristics of elements. For example, a directive such as built-in NgStyle in the template Syntax guide is an attribute directive.

5) What is the difference among "declarations", "providers" and "import" in NgModule?

Difference among declarations", "providers" and "import" in NgModule:
  • declarations are used to make directives (including components and pipes) from the current module available to other directives in the current module. Selectors of directives, components or pipes are only matched against the HTML if they are declared or imported.
  • providers are used to make services and values known to DI. They are added to the root scope and they are injected to other services or directives that have them as dependency. A special case for providers is lazy loaded modules that get their own child injector. Providers of a lazy loaded module are only provided to this lazy loaded module by default (not the whole application as it is with other modules).
  • import makes the exported declarations of other modules available in the current module.

6) What are the key components of Angular?

Key components of Angular:
Components: Components are the basic building blocks of angular application and used to control HTML views.
Modules: Modules are the set of angular basic building blocks like component, directives, services etc. An application is divided into logical pieces and each piece of code is called as "module" and used to perform a single task.
Templates: Templates are used to represent the views of an Angular application.
Services: It is used to create components which can be shared across the entire application.
Metadata: This can be used to add more data to an Angular class.

7) Explain the Architecture overview of Angular.

Angular is the most popular web development framework for developing mobile and web applications. It uses cross platform mobile development called IONIC that's why it is not limited to web apps only.
There are 7 main building blocks of an Angular application:
  • Component
  • Templates
  • Metadata
  • Data Binding
  • Directives
  • Services
  • Dependency Injection
The basic building blocks of an Angular application are NgModules, which provide a compilation context for components. Angular app is defined by a set of NgModules and it always has at least a root module that enables bootstrapping, and many more feature modules.
  • Components define Template views
  • Components use services
The NgModules make developers to organize an application into connected blocks of functionality.
The NgModule properties for the minimum "AppModule" generated by the CLI are as follows:
  • Declarations: Use to declare the application components.
  • Imports: Every application must import BrowserModule to run the app in a browser.
  • Providers: There are none to start.
  • Bootstrap: This is a root AppComponent that Angular creates and inserts into the index.html host web page.

8) How would you update Angular 6 to Angular 7?

You can update Angular 6 to Angular 7 by using the following command:
  1. ng update @angular/cli @angular/core   

9) What is the UrlSegment Interface in Angular 7?

In Angular 7, the UrlSegment interface represents a single URL segment, constructor, properties and methods like this:
  1. class UrlSegment {  
  2. constructor(path: string, parameters: {...})  
  3. path: string  
  4. parameters: {...}  
  5. toString(): string  
  6. }  
The UrlSegment is a part of a URL between the two slashes and it contains a path and matrix parameters associated with the segment.

10) What is Do Bootstrap (ng Do Bootstrap) In Angular 7?

The ng Do Bootstrap is a new life-cycle hook added in Angular 7 and Do Bootstrap is an interface.
Example
  1. //ng Do Bootstrap - Life-Cycle Hook Interface  
  2. classApp Module implements Do Bootstrap {  
  3. ng Do Bootstrap(appRef: ApplicationRef) {  
  4. appRef.bootstrap(AppComponent);  
  5.   }  
  6. }  

11) What are directives in Angular7?

In Angular7, directives are used to add behavior to an existing DOM element or an existing component instance.
For Example
  1. import { Directive, ElementRef, Input } from '@angular/core';  
  2. @Directive({ selector: '[myHighlight]' })  
  3. export class HighlightDirective {  
  4.     constructor(el: ElementRef) {  
  5.        el.nativeElement.style.backgroundColor = 'green';  
  6.     }  
  7. }  
Now this directive extends HTML element behavior with a green background as below:
Highlight me!

12) What are components in Angular7?

Components are the basic building blocks of an Angular app formed like a tree structure. Components are subset of directives but unlike directives, components always have a template and only one component can be instantiated per an element in a template.
For example:
  1. import { Component } from '@angular/core';  
  2. @Component ({  
  3.    selector: 'my-app',  
  4.    template: ` <div>  
  5.       <h1>{{title}}</h1>  
  6.       <div>Learn Angular6 with examples</div>  
  7.    </div> `,  
  8. })  
  9. export class AppComponent {  
  10.    title: string = 'Welcome to Angular world';  
  11. }  

13) What is the difference between component and directive?

A component (@component) is a directive with a template. Some major difference between components and directives are:
ComponentDirective
If you register a component, you have to use @Component meta-data annotationIf you register a directive, you have to use @Directive meta-data annotation
Components are used to break up the application into smaller components.Directives are used to design re-usable components.
Components are used to create UI widgets.Directives are used to add behavior to an existing DOM element.
Only one component can be present per DOM element.Many directives can be used per DOM element.
@View decorator or templateurl/template are mandatoryDirectives don't use View.

14) What is a template in Angular7?

A template is a HTML view where you display your data by binding controls to Angular component's properties. You can store your component's template in one of two places. You can define it inline using the template property, or you can define the template in a separate HTML file and link to it in the component metadata using the @Component decorator's templateUrl property.
For example:
Using inline template with template syntax
  1. import { Component } from '@angular/core';  
  2. @Component ({  
  3.    selector: 'my-app',  
  4.    template: '  
  5.       <div>  
  6.          <h1>{{title}}</h1>  
  7.          <div>Learn Angular</div>  
  8.       </div>  
  9.    '  
  10. })  
  11. export class AppComponent {  
  12.    title: string = 'Hello World';  
  13. }  
Using separate template file such as app.component.html
  1. import { Component } from '@angular/core';  
  2. @Component ({  
  3.    selector: 'my-app',  
  4.    templateUrl: 'app/app.component.html'  
  5. })  
  6. export class AppComponent {  
  7.    title: string = 'Hello World';  
  8. }  

15) What is a module?

Modules are the logical boundaries in the application. An application is divided into separate modules to separate the functionalities of the application.
For example: app.module.ts root module declared with @NgModule decorator
  1. import { NgModule }      from '@angular/core';  
  2. import { BrowserModule } from '@angular/platform-browser';  
  3. import { AppComponent }  from './app.component';  
  4. @NgModule ({  
  5.    imports:      [ BrowserModule ],  
  6.    declarations: [ AppComponent ],  
  7.    bootstrap:    [ AppComponent ]  
  8. })  
  9. export class AppModule { }  
Here, the NgModule decorator has three options:
  • The imports option is used to import other dependent modules. The BrowserModule is required by default for any web based angular application.
  • The declarations option is used to define components in the respective module.
  • The bootstrap option tells Angular which Component to bootstrap in the application.

16) What are the new features added in Angular7?

Following is a list of new features added in Angular7:
  • Angular7 displays an elegant look in the new update.
  • It provides virtual scrolling by using the scrolling package .
  • It facilitates you to use drag and drop property by using the @angular/cdk/drag-drop module.
  • In Angular7, libraries make changes to itself automatically with the updated version of the Material design.
  • Angular7 provides better error handling for @Output if property is not initialized.
  • Angular7 provides added support for Node v10.
  • Question: What is Angular?
    Answer: Angular is a TypeScript-based open-source web application framework, developed and maintained by Google. It offers an easy and powerful way of building front end web-based applications.
    Angular integrates a range of features like declarative templates, dependency injection, end-to-end tooling, etc. that facilitates web application development.
    QuestionDefine the ng-content Directive?
    Answer: Conventional HTML elements have some content between the tags. For instance:
    <p>Put your paragraph here</p>
    Now consider the following example of having custom text between angular tags:
    <app-work>This won’t work like HTML until you use ng-content Directive</app-work>
    However, doing so won’t work the way it worked for HTML elements. In order to make it work just like the HTML example mentioned above, we need to use the ng-content Directive. Moreover, it is helpful in building reusable components.
    Know more about the ng-content directive.
    Question: Please explain the various features of Angular.
    Answer: There are several features of Angular that makes it an ideal front end JavaScript framework. Most important of them are described as follows:
    • Accessibility Applications
    Angular allows creating accessible applications using ARIA-enabled components, built-in a11y test infrastructure, and developer guides.
    • Angular CLI
    Angular provides support for command line interface tools. These tools can be used for adding components, testing, instant deploying, etc.
    • Animation Support
    Angular’s intuitive API allows the creation of high-performance, complex animation timelines with very little code.
    • Cross-Platform App Development
    Angular can be used for building an efficient and powerful desktop, native, and progressive web apps. Angular provides support for building native mobile applications using Cordova, Ionic, or NativeScript.
    Angular allows creating high performance, offline, and zero-step installation progressive web apps using modern web platform capabilities. The popular JS framework can also be used for building desktop apps for Linux, macOS, and Windows.
    • Code Generation
    Angular is able to convert templates into highly-optimized code for modern JavaScript virtual machines.
    • Code Splitting
    With the new Component Router, Angular apps load quickly. The Component Router offers automatic code-splitting so that only the code required to render the view that is requested by a user is loaded.
    • Synergy with Popular Code Editors and IDEs
    Angular offers code completion, instant errors, etc. with popular source code editors and IDEs.
    • Templates
    Allows creating UI views with a simple and powerful template syntax.
    • Testing
    Angular lets you carry out frequent unit tests using Karma. The Protractor allows running faster scenario tests in a stable way.
    QuestionDemonstrate navigating between different routes in an Angular application.
    Answer: Following code demonstrates how to navigate between different routes in an Angular app dubbed “Some Search App”:
    import {Router} from "@angular/router";
    .
    .
    .
    @Component({
      selector: 'app-header',
      template: `
    <nav class="navbar navbar-light bg-faded">
      <a class="navbar-brand" (click)="goHome()">Some Search App</a> 
      <ul class="nav navbar-nav">
        <li class="nav-item">
          <a class="nav-link" (click)="goHome()">Home</a> 
        </li>
        <li class="nav-item">
          <a class="nav-link" (click)="goSearch()">Search</a> 
        </li>
      </ul>
    </nav>
     `
    })
    class HeaderComponent {
      constructor(private router: Router) {} 
      goHome() {
        this.router.navigate(['']); 
      }
      goSearch() {
        this.router.navigate(['search']); 
      }
    }
    Question: Could you explain services in Angular?
    Answer: Singleton objects in Angular that get instantiated only once during the lifetime of an application are called services. An Angular service contains methods that maintain the data throughout the life of an application.
    The primary intent of an Angular service is to organize as well as share business logic, models, or data and functions with various components of an Angular application.
    The functions offered by an Angular service can be invoked from any Angular component, such as a controller or directive.
    Question: Discuss the advantages and disadvantages of using Angular?
    Answer: Following are the various advantages of using Angular:
    • Ability to add a custom directive
    • Exceptional community support
    • Facilitates client and server communication
    • Features strong features, such as Animation and Event Handlers
    • Follows the MVC pattern architecture
    • Offers support for static template and Angular template
    • Support for two-way data-binding
    • Supports dependency injection, RESTful services, and validations
    Disadvantages of using Angular are enumerated as follows:
    • Complex SPAs can be inconvenient and laggy to use due to their size
    • Dynamic applications do not always perform well
    • Learning Angular requires a decent effort and time
    QuestionEnumerate some salient features of Angular 7.
    Answer: Unlike the previous versions of Angular, the 7th major release comes with splitting in @angular/core. This is done in order to reduce the size of the same. Typically, not each and every module is required by an Angular developer. Therefore, in Angular 7 each split of the @angular/core will have no more than 418 modules.
    Also, Angular 7 brings drag-and-drop and virtual scrolling into play. The latter enables loading as well as unloading elements from the DOM. For virtual scrolling, the latest version of Angular comes with the <cdk-virtual-scroll-viewport> package. Furthermore, Angular 7 comes with a new and enhanced version of the ng-compiler.
    Question: What is string interpolation in Angular?
    Answer: Also referred to as moustache syntax, string interpolation in Angular refers to a special type of syntax that makes use of template expressions in order to display the component data. These template expressions are enclosed within double curly braces i.e. {{ }}.
    The JavaScript expressions that are to be executed by Angular are added within the curly braces and the corresponding output is embedded into the HTML code. Typically, these expressions are updated and registered like watches as a part of the digest cycle.
    QuestionExplain Angular Authentication and Authorization.
    Answer: The user login credentials are passed to an authenticate API, which is present on the server. Post server-side validation of the credentials, a JWT (JSON Web Token) is returned. The JWT has information or attributes regarding the current user. The user is then identified with the given JWT. This is called authentication.
    Post logging-in successfully, different users have a different level of access. While some may access everything, access for others might be restricted to only some resources. The level of access is authorization.
    Here is a detailed post on Angular 7 – JWT Authentication Example & Tutorial: http://jasonwatmore.com/post/2018/11/16/angular-7-jwt-authentication-example-tutorial
    Question: Can you explain the concept of scope hierarchy in Angular?
    Answer: Angular organizes the $scope objects into a hierarchy that is typically used by views. This is known as the scope hierarchy in Angular. It has a root scope that can further contain one or several scopes called child scopes.
    In a scope hierarchy, each view has its own $scope. Hence, the variables set by a view’s view controller will remain hidden to other view controllers. Following is a typical representation of a Scope Hierarchy:
    • Root $scope
      • $scope for Controller 1
      • $scope for Controller 2
      • ..
      • .
      • $scope for Controller n
    QuestionHow to generate a class in Angular 7 using CLI?
    Answer:
    ng generate class Dummy [options]
    This will generate a class named Dummy.
    Question: Explain what is the difference between Angular and backbone.js?
    Answer: Following are the various notable differences between Angular and Backbone.js
    • Architecture
    Backbone.js makes use of the MVP architecture and doesn’t offer any data binding process. Angular, on the contrary, works on the MVC architecture and makes use of two-way data binding for driving application activity.
    • Community Support
    Being backed by Google greatly ups the community support received by the Angular framework. Also, extensive documentation is available. Although Backbone.js has a good level of community support, it only documents on Underscore.js templates, not much else.
    • Data Binding
    Angular uses two-way data binding process and thus is a bit complex. Backbone.js, on the contrary, doesn’t have any data binding process and thus, has a simplistic API.
    • DOM
    The prime focus of Angular JS is upon valid HTML and dynamic elements that imitate the underlying data for rebuilding the DOM as per the specified rules and then works on the updated data records.
    Backbone.js follows the direct DOM manipulation approach for representing data and application architecture changes.
    • Performance
    Thanks to its two-way data binding functionality, Angular offers an impactful performance for both small and large projects.
    Backbone.js has a significant upper hand in performance over Angular in small data sets or small webpages. However, it is not recommended for larger webpages or large data sets due to the absence of any data binding process.
    • Templating
    Angular supports templating via dynamic HTML attributes. These are added to the document to develop an easy to understand application at a functional level. Unlike Angular, Backbone.js uses Underscore.js templates that aren’t fully-featured as Angular templates.
    • The Approach to Testing
    The approach to testing varies greatly between Angular and Backbone.js due to the fact that while the former is preferred for building large applications the latter is ideal for developing smaller webpages or applications.
    For Angular, unit testing is preferred and the testing process is smoother through the framework. In the case of Backbone.js, the absence of a data binding process allows for a swift testing experience for a single page and small applications.
    • Type
    Angular is an open-source JS-based front-end web application framework that extends HTML with new attributes. On the other hand, Backbone.js is a lightweight JavaScript library featuring a RESTful JSON interface and MVP framework.
    QuestionHow do Observables differ from Promises?
    Answer: As soon as a promise is made, the execution takes place. However, this is not the case with observables because they are lazy. This means that nothing happens until a subscription is made. While promises handle a single event, observable is a stream that allows passing of more than one event. A callback is made for each event in an observable.
    Question: Please explain the difference between Angular and AngularJS?
    Answer: Various differences between Angular and AngularJS are stated as follows:
    • Architecture – AngularJS supports the MVC design model. Angular relies on components and directives instead
    • Dependency Injection (DI) – Angular supports a hierarchical Dependency Injection with unidirectional tree-based change detection. AngularJS doesn’t support DI
    • Expression Syntax – In AngularJS, a specific ng directive is required for the image or property and an event. Angular, on the other hand, use () and [] for blinding an event and accomplishing property binding, respectively
    • Mobile Support – AngularJS doesn’t have mobile support while Angular does have
    • Recommended Language – While JavaScript is the recommended language for AngularJS, TypeScript is the recommended language for Angular
    • Routing – For routing, AngularJS uses $routeprovider.when() whereas Angular uses @RouteConfig{(…)}
    • Speed – The development effort and time are reduced significantly thanks to support for two-way data binding in AngularJS. Nonetheless, Angular is faster thanks to upgraded features
    • Structure – With a simplified structure, Angular makes the development and maintenance of large applications easier. Comparatively, AngularJS has a less manageable structure
    • Support – No official support or updates are available for the AngularJS. On the contrary, Angular has active support with updates rolling out every now and then
    QuestionObserve the following image:
    Angular Interview Questions-1
    Question: Could you explain the concept of templates in Angular?
    Answer: Written with HTML, templates in Angular contains Angular-specific attributes and elements. Combined with information coming from the controller and model, templates are then further rendered to cater the user with the dynamic view.
    Question: What should replace the “?”?
    Answer: Directives. The image represents the types of directives in Angular; Attribute, structural, and custom.
    Question: Explain the difference between an Annotation and a Decorator in Angular?
    Answer: In Angular, annotations are used for creating an annotation array. They are only metadata set of the class using the Reflect Metadata library.
    Decorators in Angular are design patterns used for separating decoration or modification of some class without changing the original source code.
    Question: What are directives in Angular?
    Answer: Directives are one of the core features of Angular. They allow an Angular developer to write new, application-specific HTML syntax. In actual, directives are functions that are executed by the Angular compiler when the same finds them in the DOM. Directives are of three types:
    • Attribute Directives
    • Component Directives
    • Structural Directives
    QuestionWhat are the building blocks of Angular?
    Answer: There are essentially 9 building blocks of an Angular application. These are:
    1. Components – A component controls one or more views. Each view is some specific section of the screen. Every Angular application has at least one component, known as the root component. It is bootstrapped inside the main module, known as the root module. A component contains application logic defined inside a class. This class is responsible for interacting with the view via an API of properties and methods.
    2. Data Binding – The mechanism by which parts of a template coordinates with parts of a component is known as data binding. In order to let Angular know how to connect both sides (template and its component), the binding markup is added to the template HTML.
    3. Dependency Injection (DI) – Angular makes use of DI to provide required dependencies to new components. Typically, dependencies required by a component are services. A component’s constructor parameters tell Angular about the services that a component requires. So, a dependency injection offers a way to supply fully-formed dependencies required by a new instance of a class.
    4. Directives – The templates used by Angular are dynamic in nature. Directives are responsible for instructing Angular about how to transform the DOM when rendering a template. Actually, components are directives with a template. Other types of directives are attribute and structural directives.
    5. Metadata – In order to let Angular know how to process a class, metadata is attached to the class. For doing so decorators are used.
    6. Modules – Also known as NgModules, a module is an organized block of code with a specific set of capabilities. It has a specific application domain or a workflow. Like components, any Angular application has at least one module. This is known as the root module. Typically, an Angular application has several modules.
    7. Routing – An Angular router is responsible for interpreting a browser URL as an instruction to navigate to a client-generated view. The router is bound to links on a page to tell Angular to navigate the application view when a user clicks on it.
    8. Services – A very broad category, a service can be anything ranging from a value and function to a feature that is required by an Angular app. Technically, a service is a class with a well-defined purpose.
    9. Template – Each component’s view is associated with its companion template. A template in Angular is a form of HTML tags that lets Angular know that how it is meant to render the component.
    Question: Please explain the differences between Angular and jQuery?
    Answer: The single biggest difference between Angular and jQuery is that while the former is a JS frontend framework, the latter is a JS library. Despite this, there are some similarities between the two, such as both features DOM manipulation and provides support for animation.
    Nonetheless, notable differences between Angular and jQuery are:
    • Angular has two-way data binding, jQuery does not
    • Angular provides support for RESTful API while jQuery doesn’t
    • jQuery doesn’t offer deep linking routing though Angular supports it
    • There is no form validation in jQuery whereas it is present in Angular
    Question: Could you explain the difference between Angular expressions and JavaScript expressions?
    Answer: Although both Angular expressions and JavaScript expressions can contain literals, operators, and variables, there are some notable dissimilarities between the two. Important differences between Angular expressions and JavaScript expressions are enlisted below:
    • Angular expressions support filters while JavaScript expressions do not
    • It is possible to write Angular expressions inside the HTML tags. JavaScript expressions, contrarily, can’t  be written inside the HTML tags
    • While JavaScript expressions support conditionals, exceptions, and loops, Angular expressions don’t
    Question: Can you give us an overview of Angular architecture?
    Answer: You can draw some like this:
    Overview-of-Angular-architecture
    Here is Angular Architecture in detail: https://angular.io/guide/architecture
    QuestionWhat is Angular Material?
    Answer: It is a UI component library. Angular Material helps in creating attractive, consistent, and fully functional web pages as well as web applications. It does so while following modern web design principles, including browser portability and graceful degradation.
    QuestionWhat is AOT (Ahead-Of-Time) Compilation?
    Answer: Each Angular app gets compiled internally. The Angular compiler takes in the JS code, compiles it and then produces some JS code. This happens only once per occasion per user. It is known as AOT (Ahead-Of-Time) compilation.
    QuestionWhat is Data Binding? How many ways it can be done?
    Answer: In order to connect application data with the DOM (Data Object Model), data binding is used. It happens between the template (HTML) and component (TypeScript). There are 3 ways to achieve data binding:
    1. Event Binding – Enables the application to respond to user input in the target environment
    2. Property Binding – Enables interpolation of values computed from application data into the HTML
    3. Two-way Binding – Changes made in the application state gets automatically reflected in the view and vice-versa. The ngModel directive is used for achieving this type of data binding.
    QuestionWhat is demonstrated by the arrow in the following image?
    Angular dependency injection
    Answer: This represents a dependency injection or DI.
    Question: Can you draw a comparison between the service() and the factory() functions?
    Answer: Used for the business layer of the application, the service() function operates as a constructor function. The function is invoked at runtime using the new keyword.
    Although the factory() function works in pretty much the same way as the service() function does, the former is more flexible and powerful. In actual, the factory() function are design patterns that help in creating objects.
    Question: Please explain the digest cycle in Angular?
    Answer: The process of monitoring the watchlist in order to track changes in the value of the watch variable is termed the digest cycle in Angular. The previous and present versions of the scope model values are compared in each digest cycle.
    Although the digest cycle process gets triggered implicitly, it is possible to start it manually by using the $apply() function.
    Question: Could you explain the various types of filters in Angular.
    Answer: In order to format the value of expression so that it can be displayed to the user, Angular has filters. It is possible to add these filters to the controllers, directives, services, or templates. Angular also provides support for creating custom filters.
    Organizing data in such a way so that it is displayed only when certain criteria are fulfilled is made possible using filters. Filters are added to the expressions using the pipe ‘|’ character. Various types of Angular filters are enumerated as follows:
    • currency – Formats a number to the currency format
    • date – Formats a data to some specific format
    • filter – Selects a subset of items from an array
    • json – Formats an object to a JSON string
    • limitTo – Limits an array or string into a specified number of characters or elements
    • lowercase – Formats a string to lowercase
    • number – Formats a number to a string
    • orderBy – Orders an array by an expression
    QuestionWhat is new in Angular 6?
    Answer: Here are some of the new aspects introduced in Angular 6:
    • Angular Elements – It allows converting Angular components into web components and embeds the same in some non-Angular application
    • Tree Shakeable Provider – Angular 6 introduces a new way of registering a provider directly inside the @Injectable() decorator. It is achieved by using the providedIn attribute
    • RxJS 6 – Angular 6 makes use of RxJS 6 internally
    • i18n (internationalization) – Without having to build the application once per locale, any Angular application can have “runtime i18n”
    QuestionWhat is ngOnInit ()? How to define it?
    Answer: ngOnInit () is a lifecycle hook that is called after Angular has finished initializing all data-bound properties of a directive. It is defined as:
    Interface OnInit {
               ngOnInit () : void
          }
    QuestionWhat is SPA (Single Page Application) in Angular? Contrast SPA technology with traditional web technology?
    Answer: In the SPA technology, only a single page, which is index.HTML, is maintained although the URL keeps on changing. Unlike the traditional web technology, SPA technology is faster and easy to develop as well.
    In the conventional web technology, as soon as a client requests a webpage, the server sends the resource. However, when again the client requests for another page, the server responds again with sending the requested resource. The problem with this technology is that it requires a lot of time.
    QuestionWhat is the code for creating a decorator?
    Answer: We create a decorator called Dummy:
         function Dummy(target) {
            dummy.log('This decorator is Dummy', target);
         }
    QuestionWhat is the process called by which TypeScript code is converted into JavaScript code?
    Answer: It is called Transpiling. Even though TypeScript is used for writing code in Angular applications, it gets internally transpiled into equivalent JavaScript.
    QuestionWhat is ViewEncapsulation and how many ways are there do to do it in Angular?
    Answer: To put simply, ViewEncapsulation determines whether the styles defined in a particular component will affect the entire application or not. Angular supports 3 types of ViewEncapsulation:
    • Emulated – Styles used in other HTML spread to the component
    • Native – Styles used in other HTML doesn’t spread to the component
    • None – Styles defined in a component are visible to all components of the application
    QuestionWhy prioritize TypeScript over JavaScript in Angular?
    Answer: TypeScript is developed by Microsoft and it is a superset of JavaScript. The issue with JS is that it isn’t a true OOP language. As the JS code doesn’t follow the Prototype Pattern, the bigger the size of the code the messier it gets. Hence, it leads to difficulties in maintainability as well as reusability. To offset this, TypeScript follows a strict OOP approach.

Comments

Post a Comment

AB InfoTech

reach out : abinfotechnology@gmail.com