AngularJS Interview Questions – Set 01

What is the factory method in AngularJS?

Factory method is used for creating a directive. Whenever the compiler matches the directive for the first time, the factory method is invoked. Factory method is invoked using $injector.invoke.

Syntax

module.factory(‘factoryName’, function);

What is the Global API in AngularJS?

Global API is the combination of global JavaScript function, which is used to perform tasks such as comparing objects, iterating objects, and converting the data.

There are a few common API functions like:

  • angular.lowercase
    It is used to convert a string to lowercase string.
  • angular.uppercase
    It is used to convert a string to uppercase string.
  • angular.IsString
    It returns true if the current reference is a string.
  • angular.IsNumber
    It returns true if the current reference is a number.

How will you explain deep linking in AngularJS?

Deep linking is the method which allows us to encode the state of the application in the URL in such a way that it can be bookmarked. Then the application can further be restored from the URL to the same state.

What is Single Page Application (SPA)?

A single page application is a web application or a website which provides a very fast and reactive experience to the users like a desktop application. It only reloads the current page rather that the entire application that’s why it is extremely fast.

What is the main purpose of $routeProvider in AngularJS?

$routeProvider is one of the important services which set the configuration of URLs. It further maps them with the corresponding HTML pages or ng-templates and attaches a controller with the same.

What is $scope?

A $scope is an object that represents the application model for an Angular application.

Each AngularJS application can have only one root scope but can have multiple child scopes. For example:

var app = angular.module(‘myApp’, []);
app.controller(‘myCtrl’, function($scope) {
$scope.carname = “Volvo“;
});
Some of the key characteristics of the $scope object are given below:

  • It provides observers to check for all the model changes.
  • It provides the ability to propagate model changes through the application as well as outside the system to other associated components.
  • Scopes can be nested in a way that they can isolate functionality and model properties.
  • It provides an execution environment in which expressions are evaluated.

What are the uses of controllers in AngularJS?

AngularJS controllers are used for:

  • Setting the initial state of the $scope object
  • Adding behavior to the $scope object

How will you explain Auto Bootstrap Process in AngularJS?

AngularJS initializes automatically upon the “DOMContentLoaded” event. It also initializes when the browser downloads the Angular.js script and document.readyState is set to ‘complete’ at the same time. AngularJS looks for an ng-app directive which is the root of Angular application compilation process.

If the directive ‘ng-app’ is found, then AngularJS will perform the following steps:

  • It will load the module which is associated with the directive.
  • It will create the application injector.
  • It will compile the DOM starting from the ng-app root element.
    This process is known as Auto-bootstrapping.

How will you explain the concept of hierarchy? How many scopes can an application have?

Each Angular application contains one root scope, but there can be several child scopes. The application may have multiple scopes because child controllers and some directives create new child scopes. When the new scope is formed or created, it is added as a child of the parent scope. As similar to DOM, scopes also create a hierarchical structure.

Is AngularJS well-suited with all browsers?

Yes, AngularJS is supported with all the browsers like Safari, Chrome, Mozilla, Opera, and Internet Explorer, etc. It is also companionable with mobile browsers.