Angular JS Interview Questions



21. How AngularJS expressions are different from the JavaScript expressions?  

AngularJS expressions are much like JavaScript expressions but they are different from JavaScript expressions in the following ways:

  • Angular expressions can be added inside the HTML templates.
  • Angular expressions doesn't support control flow statements (conditionals, loops, or exceptions).
  • Angular expressions support filters to format data before displaying it.


22. What are Directives in AngularJS?  

AngularJS directives are a combination of AngularJS template markups (HTML attributes or elements, or CSS classes) and supporting JavaScript code. The JavaScript directive code defines the template data and behaviors of the HTML elements. AngularJS directives are used to extend the HTML vocabulary i.e. they decorate html elements with new behaviors and help to manipulate html elements attributes in interesting way. There are some built-in directives provided by AngularJS like as ng-app, ng-controller, ng-repeat, ng-model etc.



23. What is the role of ng-app, ng-init and ng-model directives?  

The main role of these directives is explained as:
  • ng-app - Initialize the angular app.
  • ng-init - Initialize the angular app data.
  • ng-model - Bind the html elements like input, select, text area to angular app model.


24. Is AngularJS a library, framework, plugin or a browser extension?  

AngularJS fits the definition of a framework the best, even though it's much more lightweight than a typical framework and that's why many confuse it with a library. AngularJS is 100% JavaScript, 100% client side and compatible with both desktop and mobile browsers. So it's definitely not a plugin or some other native browser extension.




25. Explain what Angular JS 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 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 configuration injected into factories, services or controllers. A value should be belong 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.



26. Why is this project called "AngularJS"? Why is the namespace called "ng"?  

Because HTML has Angular brackets and "ng" sounds like "Angular".


27. Can you explain what is testability like in Angular?  

Very testable and designed this way from ground up. It has an integrated dependency injection framework, provides mocks for many heavy dependencies (server-side communication).



28. Is AngularJS a templating system?  

At the highest level, Angular does look like a just another templating system. But there is one important reason why the Angular templating system is different, that makes it very good fit for application development: bidirectional data binding. The template is compiled in the browser and the compilation step produces a live view. This means you, the developers, don't need to write code to constantly sync the view with the model and the model with the view as in other templating systems.



29. What is a scope in AngularJS?  

scope is an object that refers to the application model. It is the glue between application controller and the view. Both the controllers and directives have reference to the scope, but not with each other. It is an execution context for expressions and arranged in hierarchical structure. Scopes can watch expressions and propagate events.



30. Do I need to worry about security holes in AngularJS?  

Like any other technology, AngularJS is not impervious to attack. Angular does, however, provide built-in protection from basic security holes including cross-site scripting and HTML injection attacks. AngularJS does round-trip escaping on all strings for you and even offers XSRF protection for server-side communication.

AngularJS was designed to be compatible with other security measures like Content Security Policy (CSP), HTTPS (SSL/TLS) and server-side authentication and authorization that greatly reduce the possible attack vectors and we highly recommended their use.



31. Explain what is linking function and type of linking function?  

Link combines the directives with a scope and produce a live view. For registering DOM listeners as well as updating the DOM, link function is responsible. After that 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 the 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.


32. Explain what is injector?  

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 look up an object instance by its name.



33. 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. By using $injector.invoke the factory method is invoked.


34. Mention what are the advantages and disadvantage of using Angular.js framework ?  

Following are the advantages of AngularJS:
  • AngularJS provides capability to create Single Page Application in a very clean and maintainable way.
  • AngularJS provides data binding capability to HTML thus giving user a rich and responsive experience
  • AngularJS code is unit testable.
  • AngularJS uses dependency injection and make use of separation of concerns.
  • AngularJS provides reusable components.
  • With AngularJS, developer writes less code and gets more functionality.
  • In AngularJS, views are pure html pages, and controllers written in JavaScript do the business processing.
  • AngularJS applications can run on all major browsers and smart phones including Android and iOS based phones/tablets
Following are the disadvantages of AngularJS:
  • Not Secure: Being JavaScript only framework, application written in AngularJS are not safe. Server side authentication and authorization is must to keep an application secure.
  • Not degradable: If your application user disables JavaScript then user will just see the basic page and nothing more.


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



36. Explain 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


37. Who created Angular JS ?  

Intially it was developed by Misko Hevery and Adam Abrons. Currently it is being developed by Google.


38. Brief about how Angular JS Framework is developed by Google  

Angular is built and maintained by dedicated Google engineers. This one may seem obvious, but it’s important to remember that many (not all) frameworks are made by hobbyists in the open source community. While passion and drive have forged frameworks, like Cappucino and Knockout, Angular is built and maintained by dedicated (and highly talented) Google engineers. This means you not only have a large open community to learn from, but you also have skilled, highly-available engineers tasked to help you get your Angular questions answered.

This isn’t Google’s first attempt at a JavaScript framework; they first developed their comprehensive Web Toolkit, which compiles Java down to JavaScript, and was used by the Google Wave team extensively. With the rise of HTML5, CSS3, and JavaScript, as both a front-end and back-end language, Google realized that the web was not meant to be written purely in Java.

AngularJS came about to standardize web application structure and provide a future template for how client-side apps should be developed.

Angular JS is being used by a host of applications, ranging from hobby to commercial products. Adoption of AngularJS as a viable framework for client-side development is quickly becoming known to the entire web development community.

Because AngularJS is built by Google, you can be sure that you’re dealing with efficient and reliable code that will scale with your project. If you’re looking for a framework with a solid foundation, Angular is your choice.



39. What makes angular.js better ?  

Followings are makes angular js 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:Angular.js 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 angular.js you can bootstrap your app easily using services, which auto-injected into your application in Guice like dependency injection style


40. Explain what is string interpolation in angular.js ?  

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.



.Net Interview Question

PHP Interview Question

Java Interview Question

AngularJS Interview Questions