AngularJS Interview Questions

 

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's 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 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. know more at Angular JS online training

4) 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.

5) What is Angular Expression? Explain the key difference between angular expressions and JavaScript expressions

Like JavaScript, Angular expressions are code snippets that are usually placed in binding such as {{ expression }}

The key difference between the JavaScript expressions and Angular expressions is:

  • Context: In Angular, the expressions are evaluated against a scope object, while the JavaScript expressions are evaluated against the global window
  • Forgiving: In Angular expression, evaluation is forgiving to null and undefined, while in JavaScript undefined properties generate TypeError or ReferenceError
  • No Control Flow Statements: Loops, conditionals or exceptions cannot be used in an angular expression
  • Filters: You can use filters to format data before displaying it.

6) How can you initialize a select box with options on page load?

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

  • <div ng-controller = " apps/dashboard/account " ng-switch
  • On = "! ! accounts" ng-init = " loadData ( ) ">

7) 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

8) How Angular JS routes work?

AngularJS routes enable you to create different URLs for different content in your application. Different URLs for different content enable the user to bookmark URLs to specific content. Each such bookmarkable URL in AngularJS 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 configuration injected into factories, services, or controllers. A value should belong to an AngularJS module.

Injecting a value into an AngularJS controller function is done by adding a parameter with the same name as the value know more at Angular JS Training

9) 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

10) What are the benefits of AngularJS?

Benefits of AngularJS are:

  • Registering Callbacks: There is no need to register callbacks. This makes your code simple and easy to debug.
  • Control HTML DOM programmatically: Applications which are created using Angular are not required to manipulate the DOM.
  • Transfer data to and from the UI: AngularJS helps to eliminate almost all of the boilerplate. It can validate the form, display errors, return to an internal model, and so on.
  • No initialization code: With AngularJS, you can bootstrap your app easily. You can use auto injected services into your application in Guice.

11) What is string interpolation in Angular.JS ?

In Angular.js, the compiler during the compilation process matches text and attributes. It uses interpolate service to see if they contain embedded expressions. As part of the normal digest cycle, these expressions are updated and registered as watches.

12) What are the steps for the compilation process of HTML?

Compilation of HTML process occurs in the following ways

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

13) Explain directives and their types

During compilation process, when 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.

14) Explain the linking function and its types

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

  • Pre-linking function: Pre-linking function is executed before the child elements are linked. It is not considered as a safe way for DOM transformation.
  • Post linking function: Post linking function is executed after the child elements are linked. It is safe to do DOM transformation by post-linking function

15) Explain injector in AngularJS

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

16) 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.

17) 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.

18) Explain the styling form that ngModel adds to CSS classes

NgModel adds these CSS classes to allow styling of form. Validation classes of AngularJS are:

  1. ng- valid
  2. ng- invalid
  3. ng-pristine
  4. ng-dirty

19) What are the characteristics of "Scope"?

  • To observer model mutations scopes provide APIs ($watch)
  • To propagate any model changes through the system into the view from outside of the Angular realm
  • A scope inherits properties from its parent scope, while providing access to shared model properties, scopes can be nested to isolate application components
  • Scope provides context against which expressions are evaluated

20) 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 the module gets loaded, the operation "config" uses dependency injection. know more at Angular JS Online Course

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

Comments

Popular posts from this blog

What is Azure?

SharePoint Interview Questions

Selenium Interview Questions