AngularJS – Questions & Answers

1. What is AngularJS?

AngularJS is a javascript framework. It is used for creating Single Page Applications. It extend the html with new attributes which makes it more useful for UI Developer.

2.  Explain what are the key features of AngularJS?

The key features of AngularJS are

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

3. From where we can download the AngularJS File?

There are two types of AngularJS script URLs you can point to, one for development and one for production:

  • angular.js— This is the human-readable, non-minified version, suitable for web development.
  • angular.min.js— This is the minified version, which we strongly suggest you use in production.

To point your code to an AngularJS script on the Google CDN server, use the following template. This example points to the minified version 1.5.6:

<!doctype html>
<html ng-app>
    My AngularJS App
    <script src="">

4. Explain what is scope in AngularJS?

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

5. Explain what is services in AngularJS?

In AngularJS 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.

6. What is controller in AngularJS?

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

7. Explain what are directives?

Directives are used to add new attributes of HTML.

8. What are the different types of Directive?

  1. Element directives
  2. Attribute directives
  3. CSS class directives
  4. Comment directives

9. Explain what is Angular Expression? Explain what is 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

  • 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 generates TypeError or ReferenceError
  • No Control Flow Statements:Loops, conditionals or exceptions cannot be used in an angular expression
  • Filters:To format data before displaying it you can use filters

10. What is injector?

An injector is a service locator, used to retrieve object instances.

11. What are factory method in AngularJS?

Factory method are used to create the directive. It is invoked only once, when compiler matches the directive for the first time. By using $injector.invoke the factory method is invoked.

12. What is ng-app, ng-init and ng-model?

ng-app – To initialize the Angular Application.
ng-init – To initialize the Angular Application data.
ng-model – To bind the html tags (input, select, textarea) to Angular Application Data.

13. What is Data Binding in AngularJS?

It is synchronization of data between the model(Angular Application variable) and view components (display with {{}}).

14. What are the advantages of using AngularJS?

AngularJS has several advantages in web development.

  • AngularJS supports MVC pattern
  • Supports two way data-binding
  • It has per-defined form validations
  • It supports both client server communication
  • Supports MVC pattern
  • Support static template and angular template
  • Can add custom directive
  • Supports REST full services
  • Supports form validations
  • Support both client and server communication
  • Support dependency injection
  • Event Handlers

15. What AngularJS routes does?

Angular js routes enable you to create different URLs for different content in your application.  Different URLs for different content enables user to bookmark URLs to specific content.  Each such bookmarkable URL in AngularJS is called a route

16. What makes AngularJS better?

  • Registering Callbacks:There is no need to register callbacks . This makes your code simple and easy to debug.
  • Control HTML DOM programmatically:  All the application that are created using Angular never have to manipulate the DOM although it can be done if it is required
  • Transfer data to and from the UI: AngularJS helps to eliminate almost all of the boiler plate like validating the form, displaying validation errors, returning to an internal model and so on which occurs due to flow of marshalling data
  • No initilization code: With AngularJS you can bootstrap your app easily using services, which auto-injected into your application in Guice like dependency injection style

17. Explain what is string interpolation in AngularJS?

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

18. 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

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

21. 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.

Please feel free to write your comments, suggestions or corrections.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s