AngularJS Interview Questions And Answers Pdf

1. What Is AngularJS?
Answer: It has been developed by one of the biggest technology giants Google. It is a JavaScript framework that helps you to create dynamic Web applications.

  • It supports to use HTML as the template language and enables the developer to create extended HTML tags that help to represent the application’s components more clearly. These tags make the code efficient by reducing the lines of code that a developer may need to write when using JavaScript.
  • It is open-source and licensed under the Apache License version 2.0.
  • It helps to develop a maintainable architecture that is easy to test at the client-end.

2. Explain The Steps Involved In The Boot Process For AngularJS?
Answer: Whenever a web page loads in the browser, the following steps execute in the background.

  • First, the HTML file containing the code gets loaded into the browser. After that, the JavaScript file mentioned in the HTML code gets loaded. It then creates a global object for angular. Now, the JavaScript which displays the controller functions gets executed.
  • In this step, AngularJS browses the complete HTML code to locate the views. If the same is available, then Angular links it to the corresponding controller function.
  • In this step, AngularJS initiates the execution of required controller functions. Next, it populates the views with data from the model identified by the controller. With this the page is ready.

3. Is AngularJS a library, framework, plugin or browser extension?
Answer:  AngularJS is a first-class JavaScript framework which allows you to build well structured, easily testable and maintainable front-end applications.

  • It is not a library since the library provides you limited functionality or has dependencies to other libraries.
  • It is not a plugin or browser extension since it is based on JavaScript and compatible with both desktop and mobile browsers.

4. What is the factory method in AngularJS?
Answer: 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( ‘factory name’, function );
Result: When declaring factory name as an injectable argument you will be provided with the value that is returned by invoking the function reference passed to module.factory.

5. What is ng-app, ng-init, and ng-model?
Answer: 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. It’s like a for a loop.
ng-if: Bind HTML elements with the 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.

6. What are the Filters in AngularJS?
Answer: Filters are used to format data before displaying it to the user.

  • They can be used in view templates, controllers, services and directives.
  • You can also create your own filters.
  • There are some built-in filters provided by AngularJS like Currency, Date, Number, OrderBy, Lowercase, Uppercase, etc.

7. Explain the validation feature in AngularJS?
Answer: AngularJS has some built-in validation around HTML5 input variables (text, number, URL, email, radio, checkbox) and some directives (required, pattern, minlength, maxlength, min, max).

If you want to create your own validation, it is just as simple as creating a directive to perform your validation.

8. How to read data from the server?
$https is an AngularJS service for reading data from remote servers.

$https.get(URL) is the function to use for reading server data.

9. What are different ways to create service in AngularJS?
Answer: There are five types to create service in AngularJS.

  1. Service
  2. Factory
  3. Provider
  4. Value
  5. Constant

10. What is $ watch?
Answer: When we create a data binding from somewhere in our view to a variable, it means on the $scope object, AngularJS creates a “watch” internally. 

A watch means that AngularJS watches changes in the variable on the $scope object.

11. Explain What String Interpolation Is In AngularJS?
Answer: During the compilation process, AngularJS compiler matches the text and attributes using interpolate service to see if it contains embedded expressions.

During the normal, digest life cycle, these expressions are updated and registered as watches.

12. What are the exit codes in Node.js? List some exit codes?
Answer: Exit codes are specific codes that are used to end a “process” (a global object used to represent a node process).

Examples of exit codes include:

Uncaught Fatal Exception
Fatal Error
Non-function Internal Exception Handler
Internal Exception handler Run-Time Failure
Internal JavaScript Evaluation Failure 

13. Why is consistent style important and what tools can be used to assure it?
Answer: Consistent style helps team members modify projects easily without having to get used to a new style every time. Tools that can help include Standard and ESLint.

14. What Are The Main Features Of AngularJS?
Answer: Here is the list of AngularJS features that makes it the hottest tech for web dev.

  1. Data-binding – Handles synchronization of data across model, controllers, and view.
  2. Scope – Object representing the model, acts as a glue layer between controller and view.
  3. Controllers – JS functions bound to the scope object.
  4. Services – Substitutable objects that are wired together using dependency injection. e.g. $location service.
  5. Filters – Formats the value of an expression for displaying to the user. e.g., uppercase, lowercase.
  6. Directives – These are extended HTML attributes start with the “ng-” prefix. e.g., the ng-app directive used to initialize the angular app.
  7. Templates – HTML code including AngularJS specific elements and attributes.
  8. Routing – It’s an approach to switch views.
  9. MVC pattern – A design pattern made up of three parts.
  10. Model – Represents data, could be static data from a JSON file or dynamic data from a database.
  11. View – Renders data for the user.
  12. Controller – Gives control over the model and view for collating information to the user.
  13. Deep linking – Enables the encoding of the application state in the URL and vice versa.
  14. Dependency injection – A design pattern to let the components injected into each other as dependencies.

15. Explain callback in Node.js?
Answer: A callback function is called at the completion of a given task. This allows other code to be run in the meantime and prevents any blocking. Being an asynchronous platform, Node.js heavily relies on callback. All APIs of Node are written to support callbacks.

16. Explain the role of REPL in Node.js?
Answer: As the name suggests, REPL (Read Eval Print Loop) performs the tasks of – Read, Evaluate, Print and Loop. The REPL in Node.js is used to execute ad-hoc Javascript statements. The REPL shell allows entry to javascript directly into a shell prompt and evaluates the results. For the purpose of testing, debugging, or experimenting, REPL is very critical.

17. What Are The Web Application Security Risks That A Web Developer Should Avoid While Doing Development Using AngularJS?
Answer: Following are the most critical web application development flaws that a developer should take care of:

  • Injection attack.
  • Broken Authentication and Session Management.
  • Cross-Site Scripting (XSS)
  • Insecure direct object references.
  • Security Misconfiguration.
  • Sensitive Data Exposure.
  • Missing Function Level Access Control.
  • Cross-Site Request Forgery (CSRF).
  • Using components that possess vulnerabilities.
  • In-validated redirects and forwards.

18. Explain What Directives Are? Mention Some Of The Most Commonly Used Directives In AngularJS Application?
Answer: AngularJS extends the behavior of HTML and DOM elements with new attributes called Directives. It directs the AngularJS’s HTML compiler ($compile) to attach a unique action to that DOM element. This AngularJS component starts with the prefix “ng.”

Following is the list of AngularJS built-in directives.

ng-bind – The ng-bind directive tells AngularJS to replace the content of an HTML element with the value of a given variable, or expression.

If there is any change in the value of the given variable or expression, then the content of the specified HTML element will also be updated accordingly. It supports one-way binding only.
ng-model – This directive is used to bind the value of HTML controls (input, select, text area) to application data. It is responsible for linking the view into the model. Directives such as ‘input’, ‘text area’, and ‘select’ require it. It supports two-way data binding.
ng-class – This directive dynamically binds one or more CSS classes to an HTML element. The value of the ng-class directive can be a string, an object, or an array.
ng-app – Just like the “Main()” function of Java language, this directive marks the beginning of the application to AngularJS’s HTML compiler ($compile). If we do not use this directive first, an error gets generated.
ng-init – This is used to initialize the application data so that we can use it in the block where it is declared. If an application requires local data like a single value or an array of values, this can be achieved using the ng-init directive.
ng-repeat – This repeats a set of HTML statements for the defined number of times. The set of HTML statements will be repeated once per item in a collection. This collection must be an array or an object.
We can even create custom directives and use them in our AngularJS Application.

19. What Are Different Ways To Invoke A Directive?

There are four different ways to invoke a directive in an angular application. They are as follows.

  1. As an attribute:
  2. As a class:
  3. As an element:
  4. As a comment:

20. What Is “$RootScope” In AngularJS?
Answer: Every AngularJS application has a “$rootScope” that is the top-most scope created on the DOM element. An app can have only one $rootScope which will be shared among all its components. It contains the ng-app directive. Every other scope is its child scope. It can watch expressions and propagate events. Using the root scope, we can set the value in one controller and read it from the other controller.

21. Explain The Concept Of Scope Hierarchy? How Many Scopes Can An Application Have?
Answer: Every AngularJS application consists of one root scope but may have several child scopes. As child controllers and directives create new child scopes, they get attached to the application. These new scopes get added as children of their parent scope. Similar to DOM, they also create a hierarchical structure.

22. How Is AngularJS Compiled?
Answer: Angular’s HTML compiler allows you to teach the browser, new HTML syntax. It enables the developer to attach new behaviors or attributes to any HTML element called directives. AngularJS compilation process takes place in the web browser itself. It does not involve any server-side or pre-compilation step.

AngularJS uses <$compiler> service to compile the angular HTML page. Its compilation begins after the HTML page (static DOM) is fully loaded.

It occurs in two phases.

Compile – It looks into the entire DOM and collects all of the directives. The result is a linking function.
Link – It combines the directives with a scope and produces a live view. Any changes in the get reflected in the view and any operations done by the user in the view gets reflected in the.
The concept of compile and link has come from the C language. Here the code is compiled first and then linked.

23. How Is AngularJS Compilation Different From Other JavaScript Frameworks?
Answer: Javascript frameworks like backbone and jQuery process the template as a string and returns the result as a string. You have to dump this resulting string into the DOM where you wanted it with innerHTML().

AngularJS process the template in another way. It directly works on HTML DOM rather than strings and manipulates it as required. It uses two-way data binding between the model and view to sync the data.

24. What is data binding? Explain two-way data binding?

  1. Data binding means automatic synchronous of data between model and view components.
  2. AngularJS supports two-way data binding, it treats the model as a single source of truth and view is the projection of the model. It means when we change model view gets to reflect and vice-versa.
  3. In the traditional concept, HTML pages are decided by interacting with server-side program and as we using single page application, pages are decided without any server-side interaction. So required part of the page will be updated.

25. Which is the core module in AngularJS?
Answer: ng” is the core module in AngularJS and this module will be loaded by default when the angular application has started.

26. Explain factory methods in AngularJS?
Answer: Factory methods are used for creating a directive. It can be invoked only once that is when compiler matches the directive.

27. What Is $RouteProvider In AngularJS?
Answer: $routeProvider is the primary service which set the configuration of URLs, map them to the corresponding HTML page or ng-template, and attach a controller with the same.

Let’s see the following example:

var mainApp = angular.module(“mainApp”, [‘ngRoute’]);
mainApp.config([‘$routeProvider’, function($routeProvider) {
when(‘/addEmployee’, {
templateUrl: ‘addEmployee.htm’, controller: ‘AddEmployeeController’

redirectTo: ‘/addEmployee’

Following are the important points to be considered in the above example.

routeProvider is defined as a function under the config of the mainApp module using a key as ‘$routeProvider.’
$routeProvider.when defines a URL “/addEmployee” which is then mapped to “addEmployee.htm”. This should be present in the same path as the main HTML page.
“otherwise” is used to set the default view.
“controller” is used to set the corresponding controller for the view.
Back to top

28. What Is Data Binding? How Many Types Of Data Binding Directives Are Provided By AngularJS?
Answer: Data binding is the connection bridge between view and business logic (view model) of the application. Data binding in AngularJs is the automatic synchronization between the model and view. When the model changes, the view is automatically updated and vice versa. AngularJs support one-way binding as well as two-way binding.

29. What are typings in Angular?
Answer: Typings is a way of installing the Typescript definitions using typings.json file, as it is necessary as the browser does not understand typescript natively and hence it must be transpiled first before rendering.

30. What are module loaders in Angular?
Answer: Module loaders in Angular are used to bundle different modules that contain their dependencies along with angular components into one bundle or multiple bundles (For lazy loading) and load them in the browser.

31. What is the use of systems? How is webpack better to use in Angular?
Answer: System is a client-side module bundler in angular as it loads modules (components and other files) on demand instead of loading an entire application at startup.
This largely reduces load times while starting up the app.
The upside of Webpack over Systems is that it bundles and creates a single file called bundle.js, which contains HTML, CSS, and JS, etc.
While the initial load time might take a few seconds once the app is cached it becomes lightning-fast and will lead to a large boost in performance.

32. What Is An Auto Bootstrap Process In AngularJS?
Answer: AngularJS initializes automatically upon the “DOMContentLoaded” event or when the browser downloads the angular.js script and at the same time document.readyState is set to ‘complete.’ At this point, AngularJS looks for the ng-app directive which is the root of the Angular app compilation process.

If the ng-app directive is located, then AngularJS will do the following.

Load the module associated with the directive.
Create the application injector.
Compile the DOM starting from the ng-app root element.
We term this process as Auto-bootstrapping.

33. What Is $Scope In AngularJS?
Answer: It is an application object. And behaves as the owner of the apps variables and functions. Scope object has access to both View and controller. Thus it works as a medium of communication between both of them. This object contains both data and functions. We can use it to access model data of the controller.

Following are the key characteristics of the scope object.
It provides observers to watch for all the model changes.
Provides the ability to propagate model changes through the application as well as outside the system to other associated components.
Scopes can be nested in such a way that they can isolate functionality and model properties.
Provides an execution environment in which expressions are evaluated.

34. Mention what are the styling form that model adds to CSS classes?
the model adds these CSS classes to allow styling of form as well as control:

  • ng- valid
  • ng-invalid
  • ng-pristine
  • ng-dirty

35. How to use jQuery with AngularJS?
By default, AngularJS use SQLite which is the subset of jQuery.

If you want to use jQuery then simply load the jQuery library before loading the AngularJS.

By doing so, Angular will skip SQLite and will start to use the jQuery library.

36. What Is The Manual Bootstrap Process In AngularJS?
Answer: Sometimes we may need to manually initialize the Angular app to have more control over the initialization process. We can do that by using angular.bootstrap() function within angular.element(document).ready() function. AngularJS fires this function when the DOM is ready for manipulation.

The angular.bootstrap() function takes two parameters, the document, and module name injector.

37. What Is A Controller In AngularJS?
Answer: A Controller is a set of JavaScript functions which is bound to a specified scope, the ng-controller directive. Angular creates a new instance of the Controller object to inject the new scope as a dependency. The role of the Controller is to expose data to our view via $scope and add functions to it, which contains business logic to enhance view behavior.

Controller Rules.

  • A Controller helps in setting up the initial state of the scope object and define its behavior.
  • The Controller should not be used to manipulate the DOM as it contains only business logic. Instead, for managing the DOM, we should use data binding and directives.
  • Do not use Controllers to format input. Instead, using angular form controls is recommended for that.
  • Controllers should not be used to share code or states. Instead, use angular services for it.
  • Steps For Creating A Controller.
  • It needs ng-controller directive.
  • Next step is to add Controller code to a module.
  • Name your Controller based on functionality. Its name should follow the camel case format (i.e., SampleController).
  • Set up the initial state of the scope object.
  • Declaring a Controller using ng-Controller directive-

38. What Is The Difference Between The $Watch, $Digest, And $ Apply?
Answer: In AngularJS $scope object is having different functions like $watch(), $digest() and $apply() and we will call these functions as central functions. The AngularJS central functions $watch(), $digest(), and $apply() are used to bind data to variables in view and observe changes happening in variables.
A) $Watch() –
The use of this function is to observe changes in a variable on the $scope. It triggers a function call when the value of that variable changes. It accepts three parameters: expression, listener, and equality object. Here, listener and equality objects are optional parameters. 

Note: Browse latest AngularJs Interview Questions and Angular Tutorial Videos. Here you can check Angular Training details and Angularjs Training Videos for self learning. Contact +91 988 502 2027 for more information.

Leave a Comment

Scroll to Top