AngularJS Interview Questions and Answers

1) What is AngularJS?

AngularJS is a JavaScript framework used for creating single web page applications. It allows you to use HTML as your template language and enables you to extend HTML syntax to express your application’s components clearly.

 

2) What are the key features of AngularJS?

The key features of AngularJS are:

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

3) Explain services in AngularJS

AngularJS services are the singleton objects or functions that are used for carrying out specific tasks. It holds some business logic.

4) Explain function scope in AngularJS

Scope refers to the application model. It acts like a glue between the application controller and the view. Scopes are arranged in a hierarchical structure and impersonate the DOM (Document Object Model) structure of the application. It can watch expressions and propagate events.

5) What are directives? Name some of the most commonly used directives in AngularJS application

A directive is something that introduces new syntax. They are like markers on the DOM element, which attaches a special behavior to it. In any AngularJS application, directives are the most important components.

Some of the commonly used directives are:

1) ng-model

2) ng-App

3) ng-bind

4) ng-repeat

5) ng-show

 

6) What is data binding in AngularJS?

Automatic synchronization of data between the model and view components is referred to as data binding in AngularJS. There are two ways for data binding

  1. Data mining in classical template systems
  2. Data binding in angular templates

7) Explain directives and their types

During compilation process, when a specific HTML function is triggered, it is referred to as directive. It is executed when the compiler encounters it in the DOM.

Different types of directives are:

1) Element directives

2) Attribute directives

3) CSS class directives

4) Comment directives.

8) Explain injector in AngularJS

An injector is a service locator. It is used to retrieve object instances as defined by the provider, instantiate types, invoke methods, and load modules. There is a single injector per Angular application, it helps to look up an object instance by its name.

9) What is the main difference between a link and compile in Angular.js?

  • Compile function: It is used for template DOM manipulation and collects all of the directives.
  • Link function: It is used for registering DOM listeners as well as for instance, DOM manipulation. It is executed once the template has been cloned.

10) What is the factory function in AngularJS?

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

11) What is ng-non-bindable in AngularJS?

Ng-non-bindable specifies AngularJs to not compile the HTML element and its child nodes. For example:

<title ng-non-bindable > </title>