AngularJS Interview Questions and Answers

Explain what are AngularJS routes does?

AngularJS routes enable you to create different URLs for different content in your application page without reloading the entire application. Different URLs for different content enables user to bookmark URLs to specific content. In AngularJS each such bookmarkable URL is called a route.

What are expressions in AngularJS?

Expressions are the code snippets that resolves to a value and used tobind application data to html. AngularJS expressions are placed inside {{expression}}.

What is the difference between AngularJS expressions and JavaScript expressions?

The main difference between the JavaScript expressions and Angular expressions are: 

•    TheJavaScript expressions are evaluated against the global window object, whereas in Angular the expressions are evaluatedagainst a scope object.

•    In JavaScript, undefined properties produces ReferenceError or TypeError, while In Angular expression evaluation is forgiving to undefined and null.

•    AngularJS expression doesn’t support loop, condition and exception, while java script do.

•    In AngularJS, filters can be used with expression to format data before displaying it but in JavaScript we can’t.

What is the use of filter in AngularJS?

A filter is used to format the value of expression to display the formatted output. AngularJS enables us to write our own filter.
It can be used in an expression with pipe character.
Examples
Name in lower Case: {{student.fullName() | lowercase}}

How to validate form data in AngularJS?

AngularJS has enriches client-side form filling validation. It support HTML 5 validations and also allow to creationof custom validation to validate data.
For example following can be used to track error: 
•    $dirty - states that value has been changed.
•    $invalid- states that value entered is invalid.
•    $touched-states that value has been touched.

Explain the concept of Watchers, Dirty checking and Digest cycle?

The data-bindings in AngularJS can be achieved via Watchers, Dirty checking and Digest cycle concept-
Watchers: Angular creates a watcher that observes the view property, which will be triggered whenever the model changes, allowing Angular to update the view content.
Dirty checking: It is the process to check whether the item has been changed or not by comparing a value with its previous value, and if it has changed then a change event is fired.
Digest cycle: when any change happens in the model the view gets updated. This updating of the model and the view is done by a loop called as digest cycle.

What is dependency injection and how does it work in Angular?

Dependency injection is a software design pattern where we inject the dependent objects rather than consumer creating the objects. 
There are two big benefits of DI: - Decoupling and Testing.

How to make an Ajax call using AngularJS?

AngularJS provides $http control which works as a service to make ajax call to read data from the server. The server makes a database call to get the desired records. AngularJS needs data in JSON format. Once the data is ready, $http can be used to get the data from server in the following manner:
functionajaxController($scope,$http) {
varurl="serverData.txt";
$http.get(url).success( function(response) {
   $scope.showdataonPage = response; 
});

How do we make HTTP get and post calls in Angular?

To make HTTP calls we need to use the “$http” service of Angular. In order to use the http services you need to make provide the “$http” as an input in your function parameters as shown in the below code.
$http({ method: "GET", url: "http://localhost/SomeMethod"     }).success(function (data, status, headers, config)
        {                   // Here goes code after success        }
$http({ method: "POST", url: "http://localhost/SomeMethod "}).success(function (data, status, headers, config)
    {      // Here goes code after success    }

Explain ng-app directive?

The ng-app directive is used to bootstrap an AngularJS application.It can also be used to declare module for an application and for initialize the angular expression variable.

Explain ng-controller directive?

The ng-controller directive specifies a Controller thatbind with scope to populate view from model data.

Explain ng-model directive?

The ng-model bind the view property by evaluating the expression on the current scope. If the property doesn't already exist on this scope, it will be created implicitly and added to the scope.
The two way binding can enable on property with this directive.

Latest Updates

General Knowledge of MP

Under the Madhya Pradesh Ladli Laxmi Yojana, the beneficiary is paid the total amount on attaining the age of ?

Indian Politics

Who appoints the Chairman and the Members of the Union Public Service Commission?

General Knowledge of World

Which country will host the 2022 Football World Cup?

Area

The angles of a triangle are in the ratio 2 : 4 : 3. The smallest angle of the triangle is?

Which one of the following triples does not represent the sides of a triangle?

If the perimeter of a rectangle is 10 cm and the area is 4 cm2, then its length is?

Height and Distance

An aeroplane flying at a height of 300 m above the ground passes vertically above another plane at an instant when the angles of elevation of the two planes from the same point on the ground are 60º and 45º respectively. What is the height of the lower plane from the ground?

From the top of a building 90 m high, the angles of depression of the top and the bottom of a tree are 30º and 45º respectively. What is the height of the tree?

Trigonometry

What is the value of sinx √( 1 /1+cosx + 1 /1-cosx ) ?

What is cos4 A - sin4 A / cos2 A - sin2 A equal to?

If 7sin2 x +3cos2 x = 4, 0 < x < 90º ,then what is the value of tan x?

If x = a cosθ + b sinθ and y = a sinθ - b cosθ then what is x2 + y2 equal to?

Average

The mean of 5 numbers is 15. If one more number is included, the mean of the 6 numbers becomes 17. What is the included number?

The mean marks obtained by 300 students in a subject are 60. The mean of top 100 students was found to be 80 and the mean of last 100 students was found to be 50. The mean marks of the remaining 100 students are?

In an asymmetrical distribution, of the mean and median of the distribution are 270 and 220 respectively, then the mode of the data is?

Let a, b, c, d, e, f, g be consecutive even numbers and j, k, l, m, n be consecutive odd numbers. What is the average of all the numbers?

Alligation or Mixture

25 kg of alloy X is mixed with 125 kg of alloy Y. If the amount of lead and tin in the alloy X is the ratio 1 : 2 and the amount of lead and tin in the alloy Y is in the ratio 2 : 3, then what is the ratio of lead to tin in the mixture?

Simplification

The ratio of two numbers is 1 : 5 and their product is 320. What is the difference between the square of these two numbers?