AngularJS Developer

  Home  Client Side Scripting  AngularJS Developer


“AngularJS Developer related Frequently Asked Questions by expert members with job experience as AngularJS Developer. These questions and answers will help you strengthen your technical skills, prepare for the new job interview and quickly revise your concepts”



125 AngularJS Developer Questions And Answers

81⟩ Explain me what are the basic steps to unit test an AngularJS filter?

1. Inject the module that contains the filter.

2. Provide any mocks that the filter relies on.

3. Get an instance of the filter using $filter('yourFilterName').

4. Assert your expectations.

Dependency injection is a powerful software design pattern that Angular employs to compose responsibilities through an intrinsic interface. However, for those new to the process, it can be puzzling where you need to configure and mock these dependencies when creating your isolated unit tests. The open-source project “Angular Test Patterns” is a free resource that is focused on dispelling such confusion through high-quality examples.

This question is useful since it can give you a feel for how familiar the candidate is with automated testing (TDD, BDD, E2E), as well as open up a conversation about approaches to code quality.

 177 views

82⟩ Explain me what are the advantages of using Angular.js framework?

Advantages of using Angular.js as framework are

☛ Supports two way data-binding

☛ Supports MVC pattern

☛ Support static template and angular template

☛ Can add custom directive

☛ Supports REST full services

☛ Supports form validations

☛ Support both client and server communication

☛ Support dependency injection

☛ Applying Animations

☛ Event Handlers

 178 views

83⟩ Tell me the concept of scope. How does scope inheritance work in AngularJS?

Scope is an object that represents the data-model of an AngularJS application—it is the glue between the view and the application controller. Scope inheritance closely mimics the DOM structure of the application. With the exception of isolated scopes created using custom directives, scopes follow prototypal inheritance. The code block below demonstrates typical scope inheritance.

<script>

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

myApp.controller("fruitController", function($scope) {

$scope.message = "This is a Fruit";

$scope.type = "Fruit";

});

myApp.controller("appleController", function($scope) {

$scope.message = "This is an Apple";

});

</script>

The important thing to note in the above example is that values have been set to models in fruitController, and the message in appleController has been overridden.

 175 views

84⟩ Explain me how do you reset a “$timeout”, and disable a “$watch()”?

The key to both is assigning the result of the function to a variable.

To cleanup the timeout, just “.cancel()” it:

var customTimeout = $timeout(function () {

// arbitrary code

}, 55);

$timeout.cancel(customTimeout);

The same applies to “$interval()”.

To disable a watch, just call it.

// .$watch() returns a deregistration function that we store to a variable

var deregisterWatchFn = $rootScope.$watch(‘someGloballyAvailableProperty’, function (newVal) {

if (newVal) {

// we invoke that deregistration function, to disable the watch

deregisterWatchFn();

...

}

});

 165 views

85⟩ What is lowercase filter?

Lowercase filter converts a text to lower case text.

In below example, we've added lowercase filter to an expression using pipe character. Here we've added lowercase filter to print student name in all lowercase letters.

Enter first name:<input type = "text" ng-model = "student.firstName">

Enter last name: <input type = "text" ng-model = "student.lastName">

Name in Upper Case: {{student.fullName() | lowercase}}

 177 views

86⟩ What is AngularJS boot process?

When the page is loaded in the browser, following things happen:

☛ HTML document is loaded into the browser, and evaluated by the browser. AngularJS JavaScript file is loaded; the angular global object is created. Next, JavaScript which registers controller functions is executed.

☛ Next AngularJS scans through the HTML to look for AngularJS apps and views. Once view is located, it connects that view to the corresponding controller function.

☛ Next, AngularJS executes the controller functions. It then renders the views with data from the model populated by the controller. The page gets ready.

 182 views

88⟩ What is ng-bind directive?

ng-bind directive binds the AngularJS Application data to HTML tags. ng-bind updates the model created by ng-model directive to be displayed in the html tag whenever user input something in the control or updates the html control's data when model data is updated by controller.

 180 views

91⟩ Explain data binding in AngularJS?

According to AngularJS.org, “Data-binding in Angular apps is the automatic synchronization of data between the model and view components. The way that Angular implements data-binding lets you treat the model as the single-source-of-truth in your application. The view is a projection of the model at all times. When the model changes, the view reflects the change, and vice versa.”

There are two ways of data binding:

Data mining in classical template systems

Data binding in angular templates

 172 views

93⟩ Tell me what is linking function and type of linking function?

Link combines the directives with a scope and produce a live view. For registering DOM listeners as well as updating the DOM, link function is responsible. After the template is cloned it is executed.

☛ Pre-linking function: Pre-linking function is executed before the child elements are linked. It is not considered as the safe way for DOM transformation.

☛ Post linking function: Post linking function is executed after the child elements are linked. It is safe to do DOM transformation by post-linking function

 172 views

94⟩ Tell me what makes the angular.copy() method so powerful?

It creates a deep copy of the variable.

A deep copy of a variable means it doesn’t point to the same memory reference as that variable. Usually assigning one variable to another creates a “shallow copy”, which makes the two variables point to the same memory reference. Therefore if we change one, the other changes as well

 168 views

95⟩ What is a service?

Services are JavaScript functions and are responsible to do specific tasks only. Each service is responsible for a specific task for example, $https: is used to make ajax call to get the server data. $route is used to define the routing information and so on. Inbuilt services are always prefixed with $ symbol.

 166 views

96⟩ What is uppercase filter?

Uppercase filter converts a text to upper case text.

In below example, we've added uppercase filter to an expression using pipe character. Here we've added uppercase filter to print student name in all capital letters.

Enter first name:<input type = "text" ng-model = "student.firstName">

Enter last name: <input type = "text" ng-model = "student.lastName">

Name in Upper Case: {{student.fullName() | uppercase}}

 197 views

97⟩ What is templates in AngularJS?

Templates are the rendered view with information from the controller and model. These can be a single file (like index.html) or multiple views in one page using "partials".

 175 views

99⟩ What is ng-init directive?

ng-init directive initializes an AngularJS Application data. It is used to put values to the variables to be used in the application.

 175 views

100⟩ Explain me what is scope hierarchy in AngularJS?

Scopes are controllers specific. If we define nested controllers then child controller will inherit the scope of its parent controller.

<script>

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

mainApp.controller("shapeController", function($scope) {

$scope.message = "In shape controller";

$scope.type = "Shape";

});

mainApp.controller("circleController", function($scope) {

$scope.message = "In circle controller";

});

</script>

 158 views