Angularjs interview questions and answers for freshers

What is the AngularJS?

AngularJS is an open source JavaScript framework, produced by Google, which assists with running single page apps. AngularJS goals are to augment browser based apps with the model, view, controller capability, in an effort to make both development and understanding. It extends the HTML (Hyper Text Markup Language) with new attributes which makes it is more helpful for UI Developer.

Explain what are the services in Angular.js?

In angular.js services are the singleton objects and functions that are used for carrying out specific tasks. It holds some business logic and these functions can be known as a controllers, directive, filters etc.

Define the various key features of AngularJS?

There are nine key features of AngularJS are:

  • Scope
  • Controller
  • Model
  • View
  • Services
  • Data Binding
  • Directives
  • Filters
  • Testable

Mention which language AngularJS is written?

AngularJS is writing in JavaScript.

Explain what is Context?

In AngularJS the expression are created against a scope object, but the JavaScript expressions are created against the global window.

What are directives in AngularJS?

In AngularJS the directives are used to add new attributes of HTML (Hyper Text Markup Language).

Which options on page load how you can initialize a select box?

You can initialize a select box with options on page load by using the ng-init directive

Explain AngularJS Controllers and give some example.

The controller is a constructor function in AngularJS Controller. When a controller is added to the DOM with use the ng-controller, Angular will instantiate a new controller object using constructor function.

For example,


<div ng-app="" ng-controller="StrControllerExample">
String 1: <input ng-model="str1" type="text" /><br />
String 2: <input ng-model="str2" type="text" /><br />
Full String <b> {{fullString()}}</b>
function StrControllerExample($scope) {
    $scope.str1 = "Meraj",
    $scope.str2 = "Ansari",
    $scope.fullString = function() {
        return $scope.str1+ " " + $scope.str2;

Mention what is linking function in AngularJS?

In AngularJS, link combines the directives with a scope and allows a live display. For the registering DOM listeners as well as changing the DOM link function is responsible. After the entire template is cloned it is performed.

Explain what are directives? Mention some of the most commonly used directives in Angular.js application?

A directive is something that introduces new syntax; they are like markers on DOM element which added a special behavior to it. In any Angular.js application, directives are the most important components. Generally used directives are ng-model, ng-App, ng-bind, ng-repeat, ng-show etc.

Explain what Angular JS routes do?

Angular js routes enable you to create different URLs for different content in your application. Different URLs for other content enables user to bookmark URLs to specific content. Each such bookmarkable URL in Angular.js is called a route. A value in Angular JS is a simple object. It can be a number, string or JavaScript object. Values are typically used as confi injected into factories, services or controllers. A value should be belonging to an Angular.js module.Injecting a value into an Angular.js controller function is done by adding a parameter with the same name as the value.

Mention the steps in the compilation process of HTML happen?

A compilation of HTML process occurs in following ways.

  • Using the standard browser API, first the HTML is parsed into a DOM.
  • By using the call to the $compile () method, compilation of the DOM is running. The method traverses the DOM and matches the directives.
  • Link the template with scope by calling the linking function returned from the previous step.

Explain what is directive and Mention what are the different types of Directive?

During the compilation process when specific HTML constructs are encountered a behavior or function is triggered, this function is referred as directive. It is executed when the compiler encounters it in the DOM.

Different types of directives are:

  • Element directives
  • Attribute directives
  • CSS class directives
  • Comment directives

Explain what is linking function and type of linking function?

Link combines the directives with a scope and produces a live view. For registering DOM listeners as well as updating the DOM, link function is responsible. After the template is cloned it is executed.

  • Pre-linking function: Pre-linking function is completed before the child elements are linked. It is not recognized as the safest way for DOM transformation.
  • Post linking function: Post linking function is executed after the child elements are linked. It is safe to do DOM transformations of post-linking function

How to differentiate between links and compile in angular.js?

Compile function: It is used for template DOM Manipulation and add all of the directives.

Link function: It is used for registering DOM listeners as well as instance DOM optimization. It is executed once the template has been cloned.

Explain what is factory method in angular.js?

For creating the directive, factory method is used. It is invoked only once, when compiler matches the directive for the first time. So, by using $injector.invoke the factory method is invoked.