Angular Interview Questions and Answers Set 8

71.Mention the steps for the compilation process of HTML happens?

Compilation of HTML process occurs in following ways:-

=> Using the standard browser API, first the HTML is parsed into DOM

=> By using the call to the $compile () method, compilation of the DOM is performed. The method traverses the DOM and matches the directives.

=> Link the template with scope by calling the linking function returned from the previous step.

72.Explain what is DI (Dependency Injection ) and how an object or function can get a hold of its dependencies?

DI or Dependency Injection is a software design pattern that deals with how code gets hold of its dependencies. In order to retrieve elements of the application which is required to be configured when module gets loaded , the operation “config” uses dependency injection.

These are the ways that object uses to hold of its dependencies:

Typically using the new operator, dependency can be created

By referring to a global variable, dependency can be looked up

Dependency can be passed into where it is required

73.Explain the concept of scope hierarchy? How many scope can an application have?

Each angular application consist of one root scope but may have several child scopes. As child controllers and some directives create new child scopes, application can have multiple scopes. When new scopes are formed or created they are added as a children of their parent scope. Similar to DOM, they also creates a hierarchical structure.

74.Explain how MVC is achieved with AngularJS? What are the benefits of client-side MVC, in general?

MVC is popular because it isolates the application logic from the user interface layer and supports separation of concerns. The controller receives all requests for the application and then works with the model to prepare any data needed by the view.

75.Dependency Injection is required for the following

Separating the process of creation and consumption of dependencies.

It allows us to create independent development of the dependencies.

We can change the dependencies when required.

It allows injecting mock objects as dependencies for testing.

AngularJS uses dependency with several types

Value

Factory

Service

Provider

Constant

A simple case of dependency injection in Angular js

AppModule.controller(“AppController”, function($scope, $window, $log,$http)   {   });

ANGULAR TRAINING
Weekend / Weekday Batch

76.What Is Singleton Pattern? How Does Angular Use It?

A singleton pattern is an approach that we adopt to limit the instantiation of a Class to have only one object. In Angular, the dependency injection and the services implement the singleton pattern.

Technically, if we call the “new Class()” two times without following the singleton pattern, the outcome will be two objects of the same class. Whereas a singleton enabled class will create the object first time and return the same object onwards.

77.What is an AOT compilation in Angular?

The AOT (ahead-of-time) compiler in Angular converts Angular HTML and TypeScript code into JavaScript code during the build phase, which makes the rendering process much faster. This compilation process is needed since Angular uses TypeScript and HTML code. The compiler converts the code into JavaScript, which can then be effectively used by the browser that runs our application.

78.When To Use Factory?

It is just a collection of functions, like a class. Hence, it can be instantiated in different controllers when you are using it with a constructor function.

79.Explain what is services in Angular.js ?

In angular.js services are the singleton objects or functions that are used for carrying out specific tasks. It holds some business logic and these function can be called as controllers, directive, filters and so on.

80.What are the differences between AngularJS module’s Service, Provider and Factory?

A factory is a simple function which allows adding some logic before creating the object. Service: A service is a constructor function which creates the object using new keyword. Add properties and functions to a service object by using this keyword. A provider is used to create a configurable service object. It returns value by using $get() function.