Top AngularJS Interview Questions You Must Prepare For In 2016

Recommended by 29 users

Mar 11, 2016
Top AngularJS Interview Questions You Must Prepare For In 2016
Add to Bookmark Email this Post 86.5K    2

AngularJS, the ‘Swiss army knife’ of the developer community, has been seeing exponential growth in popularity and career opportunities in the recent years. No surprises there, as the development framework is known for its ability to create single-page web applications that encompass three critical components – speed, agility and a strong community backing it up. AngularJS continues to dominate the arena of Javascript framework and has proved itself to be a worthy investment for web developers who seek to fast-track their career. To help you get started, we have compiled a list of the most frequently asked AngularJS interview questions that will help you ace the AngularJS interviews that come your way.

There has never been a better time to break into a AngularJS career path!  In case you have attended AngularJS interviews yourself or have any questions that you want us to answer for you, do feel free to add them as comments below. In the meantime, you can maximize the AngularJS career opportunities that are sure to come your way by taking AngularJS online training with Edureka. This course is updated with the new concepts added in AngularJS 2. Click below to know more.

angualrjs interview questions

AngularJS Interview Questions:

1. Explain data binding in AngularJS.

According to AngularJS.org, “Data-binding in Angular apps is the automatic synchronization of data between the model and view components. The way that Angular implements data-binding lets you treat the model as the single-source-of-truth in your application. The view is a projection of the model at all times. When the model changes, the view reflects the change, and vice versa.”

There are two ways of data binding:

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

2. Name the key features of AngularJS?

The key features of AngularJS are:

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

3. What are directives in AngularJS?

A core feature of AngularJS, directives are attributes that allow you to invent new HTML syntax, specific to your application. They are essentially functions that execute when the Angular compiler finds them in the DOM.  Some of the most commonly used directives are ng-app,ng-controller and ng-repeat.

The different types of directives are:

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

4. What are Controllers in AngularJS?

Controllers are Javascript functions which provide data and logic to HTML UI. As the name suggests, they control how data flows from the server to HTML UI.

5. What is Angular Expression? How do you differentiate between Angular expressions and JavaScript expressions?

Angular expressions are code snippets that are usually placed in binding such as {{ expression }} similar to JavaScript.

The main differences between Angular expressions and JavaScript expressions are:

  • Context : The expressions are evaluated against a scope object in Angular, while Javascript expressions are evaluated against the global window
  • Forgiving: In Angular expression, the evaluation is forgiving to null and undefined whereas in JavaScript undefined properties generate TypeError or ReferenceError
  • No Control Flow Statements: We cannot use loops, conditionals or exceptions in an Angular expression
  • Filters: In Angular unlike JavaScript, we can use filters to format data before displaying it

6. What is the difference between link and compile in Angular.js?

  • Compile function is used for template DOM Manipulation and to collect all the directives.
  • Link function is used for registering DOM listeners as well as instance DOM manipulation and is executed once the template has been cloned.

7. What are the characteristics of ‘Scope’?

Scope is an object that refers to the application model. It is an execution context for expressions. Scopes are arranged in hierarchical structure which mimic the DOM structure of the application. Scopes can watch expressions and propagate events. The characteristics of Scope are:

  • Scopes provide APIs ($watch) to observe model mutations.

  • Scopes provide APIs ($apply) to propagate any model changes through the system into the view from outside of the “Angular realm” (controllers, services, Angular event handlers).
  • Scopes can be nested to limit access to the properties of application components while providing access to shared model properties. Nested scopes are either “child scopes” or “isolate scopes”. A “child scope” (prototypically) inherits properties from its parent scope. An “isolate scope” does not. See isolated scopes for more information.
  • Scopes provide context against which expressions are evaluated. For example {{username}} expression is meaningless, unless it is evaluated against a specific scope which defines the username property.

8. What are the advantages of using Angular.js framework?

Angular.js framework has the following advantages:

  • Supports two way data-binding
  • 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
  • Applying Animations
  • Event Handlers

angularjs interview questions

9. What is the difference between AngularJS and backbone.js?

AngularJS combines the functionalities of most third party libraries and supports individual functionalities required to develop HTML5 Apps.  While Backbone.js does these jobs individually.

10. Explain what is injector in AngularJS?

An injector is a service locator, used to retrieve object instance as defined by provider, instantiate types, invoke methods, and load modules.

11. What is factory method in AngularJS?

Factory method is used for creating a directive.  It is invoked when the compiler matches the directive for the first time. We can invoke the factory method using $injector.invoke.

Syntax: module.factory( 'factoryName', function );
Result: When declaring factoryName as an injectable argument you will be provided with the value that is returned by invoking the function reference passed to module.factory.

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

  • ng-app : Initializes application.
  • ng-model : Binds HTML controls to application data.
  • ng-Controller : Attaches a controller class to view.
  • ng-repeat : Bind repeated data HTML elements. Its like a for loop.
  • ng-if : Bind HTML elements with condition.
  • ng-show : Used to show the HTML elements.
  • ng-hide : Used to hide the HTML elements.
  • ng-class : Used to assign CSS class.
  • ng-src : Used to pass the URL image etc.

13. Does Angular use the jQuery library?

Yes, Angular can use jQuery if it’s present in the app when the application is being bootstrapped. If jQuery is not present in the script path, Angular falls back to its own implementation of the subset of jQuery that we call jQLite.

14. Can AngularJS have multiple ng-app directives in a single page?

No. Only one AngularJS application can be auto-bootstrapped per HTML document. The first ngApp found in the document will be used to define the root element to auto-bootstrap as an application. If another ng-app directive has been placed then it will not be processed by AngularJS and we will need to manually bootstrap the second app, instead of using second ng-app directive.

15. Can angular applications (ng-app) be nested within each other?

No. AngularJS applications cannot be nested within each other.

16. What is internationalization and how to implement it in AngularJS?

Internationalization is a way in which you can show locale specific information on a website. AngularJS supports inbuilt internationalization for three types of filters: currency, date and numbers. To implement internalization, we only need to incorporate corresponding js according to locale of the country. By default it handles the locale of the browser.

17. On which types of component can we create a custom directive?

AngularJS provides support to create custom directives for the following:

  • Element directives − Directive activates when a matching element is encountered.
  • Attribute − Directive activates when a matching attribute is encountered.
  • CSS − Directive activates when a matching css style is encountered.
  • Comment − Directive activates when a matching comment is encountered.

18. What is $rootscope in AngularJS?

Every application has a single root scope. All other scopes are descendant scopes of the root scope. Scopes provide separation between the model and the view, via a mechanism for watching the model for changes. They also provide event emission/broadcast and subscription facility.

19. Can we have nested controllers in AngularJS?

Yes, we can create nested controllers in AngularJS. Nested controllers are defined in hierarchical manner while using in View.

20. What is bootstrapping in AngularJS?

Bootstrapping in AngularJS is nothing but initializing, or starting the Angular app. AngularJS supports automatic and manual bootstrapping.

  • Automatic Bootstrapping: this is done by adding ng-app directive to the root of the application, typically on the tag or tag if you want angular to bootstrap your application automatically. When angularJS finds ng-app directive, it loads the module associated with it and then compiles the DOM.
  • Manual Bootstrapping: Manual bootstrapping provides you more control on how and when to initialize your angular App. It is useful where you want to perform any other operation before Angular wakes up and compile the page.

21. What does SPA (Single Page Application) mean? How can we implement SPA with Angular?

Single Page Applications (SPAs) are web apps that load a single HTML page and dynamically update that page as the user interacts with the app. In an SPA the page never reloads, though parts of the page may refresh. This reduces the round trips to the server to a minimum.

It’s a concept where we create a single shell page or master page and load the webpages inside that master page instead of loading pages from the server by doing post backs. We can implement SPA with Angular using Angular routes. You can read up about SPAs here.

22. Why AngularJS?

AngularJS lets us extend HTML vocabulary for our application resulting in an expressive, readable, and quick to develop environment . Some of the advantages are:

  •     MVC implementation is done right.
  •     It extends HTML using directives, expression and data binding techniques to define a powerful HTML template.
  •     Two way data-binding, form validations, routing supports, inbuilt services.
  •     REST friendly.
  •     Dependency injection support.
  •     It helps you to structure and test your JavaScript code.

23. Is AngularJS compatible with all browsers?

Yes AngularJS is compatible with the following browsers: Safari, Chrome, Firefox, Opera 15, IE9 and mobile browsers (Android, Chrome Mobile, iOS Safari).

24. How to implement routing in AngularJS?

It is a five-step process:

  • Step 1: – Add the “Angular-route.js” file to your view.
  • Step 2: – Inject “ngroute” functionality while creating Angular app object.
  • Step 3: – Configure the route provider.
  • Step 4: – Define hyperlinks.
  • Step 5: – Define sections where to load the view.

25. Explain $q service, deferred and promises.

  • ‘Promises’ are post processing logics which are executed after some operation/action is completed whereas ‘deferred’ is used to control how and when those promise logics will execute.
  • We can think about promises as “WHAT” we want to fire after an operation is completed while deferred controls “WHEN” and “HOW” those promises will execute.
  • “$q” is the angular service which provides promises and deferred functionality.

These are some of the frequently asked AngularJS interview questions with answers. You can brush up on your knowledge of AngularJS with these blogs. You can also access a tutorial here.

Feeling overwhelmed with all the questions the interviewer might ask in your AngularJS interview? It’s never too late to strengthen your basics. Learn from industry experts on how to use AngularJS in real life use cases via a structured course.

AngularJS interview questions

Got a question for us? Please mention it in the comments section and we will get back to you.

Related Posts:

Get Started with Angular

Successful Web Development Career with AngularJS

Pallavi PoojaryAbout Pallavi Poojary (14 Posts)

Pallavi is a technology enthusiast who writes on hot technologies such as Big Data and DevOps, and industry-relevant skills like Project Management. She is a believer in transformation of careers through learning.


Share on
Comments
2 Comments
  • webspicer

    good collection of quetions

    • EdurekaSupport

      Hey webspicer, thanks for the wonderful feedback! We’re glad you liked our blog. Do subscribe to our blog to stay posted on upcoming Angular blogs. We will be coming up with more very soon. Cheers!

24 X 7 Customer Support X

  • us flag 1-800-275-9730 (Toll Free)
  • india flag +91 88808 62004