AngularJS Interview Questions and Answers

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.

Explain ng-click directive?

The ng-Click directive allows you to specify custom behavior and evaluation of expression when an element is clicked.
For ex;value of count changed when html button are clicked 
<button ng-click="count = count + 1" ng-init="count = 0">Increment</button>
count: {{count}}

Explain ng-repeat directive?

The ng-Repeat directive will repeat the instance of the element upon which it is declared for each item in a collection.

There are following variable we can used with this directive
$index : Iterator offset of the repeated element (0..length-1)
$first : True, if the repeated element is first in the iterator
$middle : True, if the repeated element is between first and last in the iterator
$last : True, if the repeated element is last in the iterator
$even : True, if the iterator position $index is even (otherwise, false)
$odd : True, if the iterator position $index is odd (otherwise, false)

Explain ng-show and ng-hide directive?

The ng-Show directive shows or hides the given HTML element based on the expression provided to the ng-Show attribute. And samethe ng-Hide directive shows or hides the given HTML element based on the expression provided to the ng-Hide attribute.

Latest Updates

Percentage

20% of a quantity is Rs 400, the quantity equals?

Time and Work

A certain piece of work can be completed by 12 men in 9 days. After they have worked for six days, six more men joined them. How many days will it take to complete the remaining work?

Ratio and Proportion

A certain sum was divided among A, B and C in the ratio 5 : 7 : 6. If B received Rs 4500 more than C, find C's share?

Problems on Ages

A is two years older than B who is twice as old as C. If the total of the ages of A, B and C be 27, the how old is A?

Time and Work

A and B can together finish a work in 30 days. They worked at it for 20 days and then B left. The remaining work was done by A alone in 20 more days. B alone can do the entire work in?

Discount

A retailer buys a washing machine marked at Rs 4800 and gets two successive discounts of 15% and 5%. If he spends Rs 124 on transportation and sells the washing machine at a gain of 13%, then find the selling price of the machine.

Boats and Streams

Speed of a boat in still water is 10 kmph, and speed of the stream is 5 Kmph. In how many minutes would the boat cover a distance of 5 km downstream?

Problems on Ages

The age of two persons differ by 2 years. If the sum of their ages is equal to the square root of 144 then find the age of the elder among the two person?

The age of A is six times the age of his son. A's father is 40 years older than him. Together, they are 118 years old. What is the age of A?

Average

The average mark of 50 students is 75. If the marks obtained by one of the student had been written as 36 instead of 86, then the corrected average of marks is:

Unix/Linux

What is inode?

Problems on Ages

A group of 15 people has average age of 45 years. Two persons are excluded and the average of the remaining is increased by 5 years. What is the average age of the two persons who have been excluded?

Average

In the world cup, Yuvraj has a batting average of 65 in 7 matches till semi-final. How much should Yuvraj score in the 8th match ie the final match to get a batting average of 85?

Problems on Trains

A train takes 8 sec to cross a 75 metre long platform at a speed of 90 km/h. What is the length of the train?

Alligation or Mixture

In what ratio must Rs 50 per kg salt be mixed with Rs 80 per kg salt to obtain a mixture worth of Rs 60 per kg?

Numbers

Find the sum of the given series: 3 + 9 + 27 + 81 + 243 + 729 + 2187 + 6561

Average

Find the average. 62, 54, 44, 36, 28 & 22

Percentage

In an examination, 36% of the students failed in English and 40% failed in Hindi. If 20% of the students failed in both subjects, then the pass percentage is?

Latest Job Notifications

Jobs in Madhya Pradesh

राष्ट्रीय स्वास्थ्य मिशन मध्य प्रदेश National Health Mission MP(NRHM) - 5215 पद - 22/06/2021 अंतिम तिथि

Jobs in Punjab

पंजाब स्टेट पावर कॉर्पोरेशन लिमिटेड Punjab State Power Corporation Limited (PSPCL) - 2632 पद - 20/06/2021 अंतिम तिथि

Jobs in Chhattisgarh

स्वास्थ्य सेवा निदेशालय, छत्तीसगढ़ Department of Health & Family Welfare, Chhattisgarh - 267 पद - 26/06/2021 अंतिम तिथि

Government Jobs

दिल्ली सबऑर्डिनेट सर्विस सिलेक्शन बोर्ड Delhi Subordinate Services Selection Board(DSSSB) - 5807 पद - 03/07/2021 अंतिम तिथि

Jobs in Madhya Pradesh

राष्ट्रीय स्वास्थ्य मिशन मध्य प्रदेश National Health Mission MP(NRHM) - 2850 पद - 31/05/2021 अंतिम तिथि

Government Jobs

इंडियन पोस्ट सर्विस Indian Post Service - 4368 पद - 29/05/2021 अंतिम तिथि

दिल्ली सबऑर्डिनेट सर्विस सिलेक्शन बोर्ड Delhi Subordinate Services Selection Board(DSSSB) - 7236 पद - 24/06/2021 अंतिम तिथि

Banking Jobs

Reserve Bank of India (RBI) - 841 Posts - 15/03/2021 Last date

Institute of Banking Personnel Selection (IBPS) - CRP SPL-IX - 1163 Posts - 26/11/2019 Last date

Government Jobs

Reserve Bank of India (RBI) - 199 Posts - 11/10/2019 Last date