AngularJS Basic Interview Questions

AngularJS Basic Interview Questions

Angularjs basic interview questions and answers

Find basic top 30 Angular js interview questions and their answers

Download AngularJS Basic Interview Questions PDF

AngularJS Basic Interview Questions

Angular filters are arguments passed to the angular expressions using pipe characters.The main use of filters is to format or alter the data and present it in a customized manner. The following in built filters are provided by angularjs framework : uppercase, lowercase, currency, filter,orderby etc.

$rootscope is the parent of all scopes while $scope is merely an object instance of a controller. $rootscope is global while $scope is local i.e. it’s available only to the controller it’s passed to.

AngularJS is an MVC framework and one of it’s most powerful feature is two-way data binding, which means that model and view are in sync all the time. If there is a change in the model value, the view gets updated automatically. Angular achieves this by running a loop known as digest cycle. Digest cycle goes through the following steps to update the view if a model has changed or vice versa :

  • Step 1: Whenever an end user triggers some kind of event like typing, button click etc, such an activity leads to the change of model data.
  • Step 2: Angular framework then checks whether the old value and the new value are same. If the values have not changed, it does nothing but if the values have changed then Digest cycle gets invoked.
  • Step 3: Digest cycle then runs through all the scope objects of the controller and checks whether any scope object has been affected due to the model change. Every scope object has watchers, these watchers listen whether the model has changed or not.Digest cycle informs these watchers about model change and then finally these watchers synchronize the view with the model data.
  • Step 4: When watchers synchronize the view with the model data, there is a possibility that model may get updated again. To make sure that this change in model gets synchronized with the view, angular runs the digest cycle once again. This second loop of digest cycle is termed as “Dirty Checking”.

Based on the expression’s boolean result, the ng-if directive removes or recreates the element in the dom. If the expression resolves to true it removes the element from the dom otherwise a clone of the element gets inserted.

Based on the expression’s boolean result,ng-show directive hides or shows the element in the dom. If the expression resolves to false it hides the element by adding ng-hide css class on the element otherwise the class is removed from the element.

Angular provides the ability to create our own directives to implement our own custom templates or logic in our web application.

For example: Say you have a template consisting of some text boxes and a submit button which is getting used in every single page of your website. Inorder to reduce the re-work, we can simply create our directive which will produce the template when the custom directive is used as an attribute or an element in an html page. In this way we can create and apply a custom directive whic are very useful.

Javascript is a light weight front end scripting language used for carrying out simple functions like changing colors, redirecting to new web pages etc. JQuery is a javascript library used for dom manipulations, enhancing browser compatibility and easing the front ed development. AngularJS is a javascript framework which helps in developing LOB web applications in MVC architectural pattern.It is idle for developing Single page applications or SPA’s.

Two-way data binding is a feature provided by the angular framework using which the view and model of an MVC application are in sync all the time i.e. change in view updates model and vice versa. To achieve two-way data binding “ng-model” directive is used. By default, ng-model provides the two-way data model functionality. In order to achieve one-way data binding, ng-model can be used in below fashion: ng-model=”::object.value”

In Angularjs, directives by default inherit all the properties from the parent scope, and while creating a custom directive one may need some parent scope properties. There is a possibility that the parent scope at some point in the application lifecycle may get removed/deleted, on the removal of that property the custom directive becomes completely useless.

So to make a custom directive that can access the parent scope properties and at the same time does not rely on it we use isolated scope.

$http is used to make ajax calls to the server. Using $http service we can send request to the server and in return we get respond and data. We can carry out all the CRUD operations using get, post, put and delete methods of $http service.

$scope is the object instance of the controller, it acts as a glue between view and model. $scope is passed as an arguement to the controller and is local to the controller it’s passed to. If controllers are nested, the child scope can access all the properties of parent scope.

A module is a block which defines the boundaries of an angular application.Outside a module ,the angular features and properties will not work. It is implemented by using the directive “ng-app” and is referenced just below the angular framework’s javascript files. It is defined in the following fashion : 

 var app = angular.module("myApp", []);

In this code snippet,”myApp” is the name of the module and is mandatory.The square brackets “[]”, help to inject dependencies in our angular application.

Dependency Injection or DI, is a design pattern of injecting objects into the angular components instead of angular components creating for themselves. The advantage of this is, we can separate our web application in multiple logical units, we can reuse these multiple logical units anywhere in our application. In angular dependency injection is the main concept without which angular does not work. For example, In order to use services(built-in or custom or both) we have to inject these services in our controller as shown below.

 //Use your $http service here 


One of the most powerful features of AngularJS is data binding.In data binding, the controller binds the data with the view. In AngularJS binding is of two types, one-way binding and two-way binding.In one way binding, the change in the model does not affect view or vice versa.But in two way binding, the change in model adjusts the view accordingly.

AngularJS is a javascript framework which helps in developing web applications in MVC architectural pattern & SPA or Single page applications. It simplifies binding of the business logic with a view.It’s an open source framework but is supported by Google.

Angular directives are the attributes which are decorated on the html tags or elements of an html page. Directives have a prefix “ng-” and are used for dom manipulations & data binding. Some of the most common directives are : ng-app, ng-controller,ng-repeat,ng-if etc.