Monday, July 29, 2019

What are basic AngularJS Interview Questions ?

A list of top frequently asked AngularJS interview questions and answers are given below.

1) What is AngularJS?

AngularJS is a JavaScript framework, i.e., used to create a single web page application. It follows MVC (Model View Controller) pattern. It is an open source, cross-browser compliant and easy to maintain.

2) What are the advantages of AngularJS?

  • Allows us to create a single page application
  • Follows MVC pattern
  • Predefined form validations
  • Supports animation
  • Open source
  • Cross-browser compliant
  • Supports two-way data binding
  • Its code is unit testable

3) What are the disadvantages of AngularJS?

  • JavaScript Dependent: If end user disables JavaScript, AngularJS will not work.
  • Not Secured: It is a JavaScript-based framework, so it is not safe to authenticate the user through AngularJS only.

4) Is AngularJS dependent on JQuery?

No. AngularJS is a JavaScript framework whereas JQuery is a JavaScript library.

5) What IDE's are currently used for the development of AngularJS?

  • Eclipse - It is one of the most popular IDE. It supports AngularJS plugins.
  • Visual Studio - It is an IDE from Microsoft that provides a platform to develop web apps easily and instantly.
  • WebStorm - It is one of the most powerful IDE for modern JavaScript development. It provides an easier way to add dependencies with angular CLI
  • Aptana - It is a customized version of Eclipse. It is free to use.
  • Sublime Text - It is one of the most recommendable editors for HTML, CSS, and JavaScript. It is very much compatible with AngularJS code.

6) What are the features of AngularJS?

  1. MVC - In AngularJS, you just have to split your application code into MVC components, i.e., Model, View and the Controller.
  2. Validations - It performs client-side form validation.
  3. Modules - It defines an application.
  4. Directives - It specifies behavior on the DOM element.
  5. Templates - It renders the dynamic view.
  6. Scope - It joins the controller with the views.
  7. Expressions - It binds application data to HTML
  8. Data Binding - It creates a two-way data-binding between the select element and the orderProp model.
  9. Filters - It provides the filter to format data.
  10. Services - It stores and shares data across the application.
  11. Routing - It is used to build a single page application.
  12. Dependency Injection - It specifies a design pattern in which components are given their dependencies instead of hardcoding them within the component.
  13. Testing - It is easy to test any of the AngularJS components through unit testing and end-to-end testing.

7) What are the directives in AngularJS?

Directives are the markers on DOM element that is used to specify behavior on that DOM element. All AngularJS directives start with the word "ng". There are many in-built directives in AngularJS such as "ng-app", "ng-model", "ng-controller", "ng-repeat" etc.
Let's see a simple example of AngularJS directive.
  1. <div ng-app = "" ng-init = "countries = [{locale:'en-IND',name:'India'}, {locale:'en-PAK',name:'Pakistan'}, {locale:'en-AUS',name:'Australia'}]">     
  2.          <p>Enter your Name: <input type = "text" ng-model = "name"></p>    
  3.          <p>Hello <span ng-bind = "name"></span>!</p>    
  4.          <p>List of Countries with locale:</p>    
  5.           
  6.          <ol>    
  7.             <li ng-repeat = "country in countries">    
  8.                {{ 'Country: ' + country.name + ', Locale: ' + country.locale }}    
  9.             </li>    
  10.          </ol>    
  11.       </div>    

8) What are the controllers in AngularJS?

Controllers are JavaScript functions that are used to provide data and logic to HTML UI. It acts as an interface between Server and HTML UI. Each controller accepts $scope as a parameter which refers to the application/module that controller is to control. For example:
  1. <script>    
  2. var app = angular.module('myApp', []);    
  3. app.controller('myCtrl', function($scope) {    
  4.     $scope.firstName = "Aryan";    
  5.     $scope.lastName = "Khanna";    
  6. });    
  7. </script>    

9) What is the usage of controllers in AngularJS?

AngularJS Controllers are used to:
  • Set up the initial state of the $scope object, and
  • Add behavior to the $scope object.

10) What is data binding in AngularJS?

Data Binding is the automatic synchronization of data between model and view. There are two ways of data binding:
  • One way data binding (used in the classical template) - Here, a value is taken from the data model and inserted into an HTML element.
  • Two-way data binding (used in the AngularJS template) - It treats the model as the single-source-of-truth in your application. The view is a projection of the model at all times. If the model is changed, the view reflects the change and vice versa.

11) What are the services in AngularJS?

Services are objects that can be used to store and share data across the application. AngularJS offers many built-in services such as $http, i.e., used to make XMLHttpRequest.

12) What is the module in AngularJS?

A module is a container for the different parts of application like controller, services, filters, directives etc. It treats as a main() method. A module is created using an angular object's module() method. For example:
  1. var app = angular.module('myApp', []);    

13) What is the scope in AngularJS?

A Scope is an object that represents the application model.
Each AngularJS application can have only one root scope but can have multiple child scopes. For example:
  1. var app = angular.module('myApp', []);    
  2. app.controller('myCtrl', function($scope) {    
  3.     $scope.carname = "Volvo";    
  4. });   

14) What is routing in AngularJS?

A routing is a mechanism that builds an application as a Single Page Application. It routes the application to different pages without reloading the application.

15) What is a template in AngularJS?

A template consists of HTML, CSS and AngularJS directives that are used to render the dynamic view.

16) What are the expressions in AngularJS?

Expressions are the code snippets that resolves to a value. AngularJS expressions are placed inside {{expression}}. For example:
  1. {{1+1}}  
AngularJS supports one-time binding expressions.

17) What is the use of a filter in AngularJS?

A filter is used to format the value of the expression to display the formatted output. AngularJS enables us to write our filter. Filters can be added to expressions by using the pipe character |, followed by a filter. For example:

  1. <div ng-app="myApp" ng-controller="personCtrl">    
  2. <p>The name is {{ firstName | uppercase }}</p>    
  3. </div>    
  4. <script>    
  5. angular.module('myApp', []).controller('personCtrl', function($scope) {    
  6.     $scope.firstName = "Sonoo",    
  7.     $scope.lastName = "Jaiswal"    
  8. });    
  9. </script>   

18) What are the different types of filters in AngularJS?

  1. Currency - It formats a number to a currency format.
  2. Date - It formats a date to a specified format.
  3. Filter - It selects a subset of items from an array.
  4. JSON - It formats an object to a Json string.
  5. Limit - It is used to limit an array/string, into a specified number of elements/characters.
  6. Lowercase - It formats a string to lower case.
  7. Number - It formats a number to a string.
  8. Orderby - It orders an array by an expression.
  9. Uppercase - It formats a string to upper case.

No comments:

Post a Comment